源代码网整理以下(1) int mysql_affected_rows([int link_id]);
在给定的连接中,返回由最近的DELETE、INSERT、REPLACE或者UPDATE语句所作用的行数。
源代码网整理以下如果没有行
被修改,则mysql_affected_rows()返回0,如果出现错误,则返回-1。
源代码网整理以下在SELECT查询之后,mysql_affected_rows()返回所选择的行数。
源代码网整理以下但一般是与SELECT语句一道使用
mysql_num_rows().
使用范例:
源代码网整理以下
|
源代码网整理以下以下为引用的内容:
源代码网整理以下<?php $link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect"); mysql_select_db("samp_db") or die("Could not select database"); $query="INSERT INTO
member(last_name,first_name,expiration)"."VALUES("Brown","Marcia","2002-6-3")"; $result=mysql_query($query) or die("Query failed"); printf("%d row%s insertedn",mysql_affected_rows(),mysql_affected_rows()==1?" ":"s"); ?>
|
(2) int mysql_close(int[link_id]);
关闭由link_id标识的与MySQL服务器的连接。
源代码网整理以下如果没有指定连接,则mysql_close()关闭最近打开的连
接。
源代码网整理以下如果成功,则mysql_close()返回真,失败则返回假。
源代码网整理以下对由mysql_pconnect()打开的永久连接,
mysql_close()忽略相应的关闭请求,只是返回值。
源代码网整理以下如果要关闭一个连接,就应该用mysql_connect()而不是
mysql_pconnect()来打开它。
使用范例:
|
源代码网整理以下以下为引用的内容:
源代码网整理以下<?php $link=mysql_connect("localhost","sunsoft","suixiang") or die("Could not connect"); print("Connected successfully"); mysql_close($link); ?>
|
(3) int mysql_connect(string [hostname] [:port], string [username], string [password]);
本函式建立与 MySQL 伺服器的连线。
源代码网整理以下其中所有的参数都可省略。
源代码网整理以下当使用本函式却不加任何参数时,参
数 hostname 的内定值为 localhost、参数 username 的内定值为 PHP 执行行程的拥有者、参数 password 则
为空字串 (即没有密码)。
源代码网整理以下而参数 hostname 后面可以加冒号与
埠号,代表使用那个埠与 MySQL 连接。
源代码网整理以下 当然在
使用资料库时,早点使用 mysql_close() 将连线关掉可以节省资源。
源代码网整理以下使用范例
这是一位未具名网友提供的范例 (18-Feb-1999)
(4) int mysql_create_db(string db_name [, int link_id]);
告诉由link_id标识的MySQL服务器用给定的名称来创建数据库。
源代码网整理以下如果数据库创建成功,则返回真;如
果出现错误,则返回假。
源代码网整理以下必须在数据库有创建它的CREATE权限。
源代码网整理以下可能利用mysql_query()较利用mysql_create_db()发布CREATE DATABASE 语句更为适合。
源代码网整理以下
|
源代码网整理以下以下为引用的内容:
源代码网整理以下<?php $dbh = mysql_connect("localhost:3306","mcclain","standard"); mysql_select_db("admreqs"); $query = "insert into requests(date, request, email, priority,status) values
(NOW(),"$description", "$email", "$priority", "NEW")"; $res = mysql_query($query, $dbh); $query = "select max(id) from requests"; $res = mysql_query($query, $dbh); $err = mysql_error(); if($err){ echo "发生错误,请通知<a href=mailto:webmaster@my.site>站长</a>"; } $row = mysql_fetch_row($res); echo "未来您使用的号码为: ".$row[0]; ?>
|