<p>mysql_affected_rows<br />
mysql_affected_rows -- 取得前一次 MySQL 操作所影响的记录行数<br />
例子 1. mysql_affected_rows() 例子<br />
<!--?php<br /--> $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');<br />
if (!$link) {<br />
die('Could not connect: ' . mysql_error());<br />
}<br />
mysql_select_db('mydb');<br />
/* 本例返回被删除记录的准确数目 */<br />
mysql_query('DELETE FROM mytable WHERE id < 10');<br />
printf("Records deleted: %dn", mysql_affected_rows());<br />
/* 对于非真值的 WHERE 子句,应返回 0 */<br />
mysql_query('DELETE FROM mytable WHERE 0');<br />
printf("Records deleted: %dn", mysql_affected_rows());<br />
?><br />
上例的输出类似于:<br />
<br />
Records deleted: 10<br />
Records deleted: 0<br />
<br />
例子 2. 使用事务处理的 mysql_affected_rows() 例子<br />
<br />
<!--?php<br /--> $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');<br />
if (!$link) {<br />
die('Could not connect: ' . mysql_error());<br />
}<br />
mysql_select_db('mydb');<br />
/* Update records */<br />
mysql_query("UPDATE mytable SET used=1 WHERE id < 10");<br />
printf ("Updated records: %dn", mysql_affected_rows());<br />
mysql_query("COMMIT");<br />
?><br />
上例的输出类似于:<br />
Updated Records: 10<br />
<br />
mysql_result<br />
mysql_result -- 取得结果数据<br />
<!--?php<br /--> $link = mysql_connect("localhost", "mysql_user", "mysql_password")<br />
or die("Could not connect: " . mysql_error());<br />
$result = mysql_query("SELECT name FROM work.employee")<br />
or die("Could not query: . mysql_error());<br />
echo mysql_result($result,2); // outputs third employee's name<br />
mysql_close($link);<br />
?><br />
<br />
mysql_num_rows<br />
mysql_num_rows -- 取得结果集中行的数目<br />
例子 1. mysql_num_rows() 例子<br />
<!--?php<br /--> $link = mysql_connect("localhost", "mysql_user", "mysql_password");<br />
mysql_select_db("database", $link);<br />
$result = mysql_query("SELECT * FROM table1", $link);<br />
$num_rows = mysql_num_rows($result);<br />
echo "$num_rows Rowsn";<br />
?><br />
<br />
mysql_num_fields<br />
mysql_num_fields -- 取得结果集中字段的数目(id,name......)<br />
<br />
mysql_free_result<br />
mysql_free_result -- 释放结果内存<br />
mysql_insert_id<br />
mysql_insert_id -- 取得上一步 INSERT 操作产生的 ID<br />
例子 1. mysql_insert_id() 例子<br />
<!--?php<br /--> mysql_connect("localhost", "mysql_user", "mysql_password") or<br />
die("Could not connect: " . mysql_error());<br />
mysql_select_db("mydb");<br />
mysql_query("INSERT INTO mytable (product) values ('kossu')");<br />
printf ("Last inserted record has id %dn", mysql_insert_id());<br />
?><br />
<br />
mysql_fetch_row<br />
mysql_fetch_row -- 从结果集中取得一行作为枚举数组<br />
<br />
mysql_fetch_field<br />
mysql_fetch_field -- 从结果集中取得列信息并作为对象返回<br />
mysql_fetch_field() 可以用来从某个查询结果中取得字段的信息。如果没有指定字段偏移量,则下一个尚未被 mysql_fetch_field() 取得的字段被提取。<br />
<br />
对象的属性为:<br />
name - 列名<br />
table - 该列所在的表名<br />
max_length - 该列最大长度<br />
not_null - 1,如果该列不能为 NULL<br />
primary_key - 1,如果该列是 primary key<br />
unique_key - 1,如果该列是 unique key<br />
multiple_key - 1,如果该列是 non-unique key<br />
numeric - 1,如果该列是 numeric<br />
blob - 1,如果该列是 BLOB<br />
type - 该列的类型<br />
unsigned - 1,如果该列是无符号数<br />
zerofill - 1,如果该列是 zero-filled<br />
注: 本函数返回的字段名是区分大小写的。<br />
例子 1. mysql_fetch_field()<br />
<!--?php<br /--> mysql_connect('localhost:3306', $user, $password)<br />
or die("Could not connect: " . mysql_error());<br />
mysql_select_db("database");<br />
$result = mysql_query("select * from table")<br />
or die("Query failed: " . mysql_error());<br />
/* get column metadata */<br />
$i = 0;<br />
while ($i < mysql_num_fields($result)) {<br />
echo "Information for column $i:<br />
n";<br />
$meta = mysql_fetch_field($result);<br />
if (!$meta) {<br />
echo "No information available<br />
n";<br />
}<br />
echo "</p>
<pre>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table: $meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
</pre>
<p>";<br />
$i++;<br />
}<br />
mysql_free_result($result);<br />
?><br />
<br />
<br />
mysql_get_server_info<br />
mysql_get_server_info -- 取得 MySQL 服务器信息<br />
例子 1. mysql_get_server_info() 例子<br />
<!--?php<br /--> mysql_connect("localhost", "mysql_user", "mysql_password") or<br />
die("Could not connect: " . mysql_error());<br />
printf ("MySQL server version: %sn", mysql_get_server_info());<br />
?><br />
<br />
strstr<br />
strstr -- Find first occurrence of a string<br />
例子 1. strstr() example<br />
<!--?php<br /--> $email = 'user@example.com';<br />
$domain = strstr($email, '@');<br />
echo $domain; // prints @example.com<br />
?><br />
<br />
mysql_escape_string<br />
mysql_escape_string -- 转义一个字符串用于 mysql_query<br />
例子 1. mysql_escape_string() 例子<br />
<!--?php<br /--> $item = "Zak's Laptop";<br />
$escaped_item = mysql_escape_string($item);<br />
printf ("Escaped string: %sn", $escaped_item);<br />
?></p>