php内置操作mysql的函数 要看的

<p>mysql_affected_rows<br /> mysql_affected_rows -- 取得前一次 MySQL 操作所影响的记录行数<br /> 例子 1. mysql_affected_rows() 例子<br /> <!--?php<br /--> $link = mysql_connect(&#39;localhost&#39;, &#39;mysql_user&#39;, &#39;mysql_password&#39;);<br /> if (!$link) {<br /> die(&#39;Could not connect: &#39; . mysql_error());<br /> }<br /> mysql_select_db(&#39;mydb&#39;);<br /> /* 本例返回被删除记录的准确数目 */<br /> mysql_query(&#39;DELETE FROM mytable WHERE id &lt; 10&#39;);<br /> printf(&quot;Records deleted: %dn&quot;, mysql_affected_rows());<br /> /* 对于非真值的 WHERE 子句,应返回 0 */<br /> mysql_query(&#39;DELETE FROM mytable WHERE 0&#39;);<br /> printf(&quot;Records deleted: %dn&quot;, mysql_affected_rows());<br /> ?&gt;<br /> 上例的输出类似于:<br /> <br /> Records deleted: 10<br /> Records deleted: 0<br /> <br /> 例子 2. 使用事务处理的 mysql_affected_rows() 例子<br /> <br /> <!--?php<br /--> $link = mysql_connect(&#39;localhost&#39;, &#39;mysql_user&#39;, &#39;mysql_password&#39;);<br /> if (!$link) {<br /> die(&#39;Could not connect: &#39; . mysql_error());<br /> }<br /> mysql_select_db(&#39;mydb&#39;);<br /> /* Update records */<br /> mysql_query(&quot;UPDATE mytable SET used=1 WHERE id &lt; 10&quot;);<br /> printf (&quot;Updated records: %dn&quot;, mysql_affected_rows());<br /> mysql_query(&quot;COMMIT&quot;);<br /> ?&gt;<br /> 上例的输出类似于:<br /> Updated Records: 10<br /> <br /> mysql_result<br /> mysql_result -- 取得结果数据<br /> <!--?php<br /--> $link = mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;)<br /> or die(&quot;Could not connect: &quot; . mysql_error());<br /> $result = mysql_query(&quot;SELECT name FROM work.employee&quot;)<br /> or die(&quot;Could not query: . mysql_error());<br /> echo mysql_result($result,2); // outputs third employee&#39;s name<br /> mysql_close($link);<br /> ?&gt;<br /> <br /> mysql_num_rows<br /> mysql_num_rows -- 取得结果集中行的数目<br /> 例子 1. mysql_num_rows() 例子<br /> <!--?php<br /--> $link = mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;);<br /> mysql_select_db(&quot;database&quot;, $link);<br /> $result = mysql_query(&quot;SELECT * FROM table1&quot;, $link);<br /> $num_rows = mysql_num_rows($result);<br /> echo &quot;$num_rows Rowsn&quot;;<br /> ?&gt;<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(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;) or<br /> die(&quot;Could not connect: &quot; . mysql_error());<br /> mysql_select_db(&quot;mydb&quot;);<br /> mysql_query(&quot;INSERT INTO mytable (product) values (&#39;kossu&#39;)&quot;);<br /> printf (&quot;Last inserted record has id %dn&quot;, mysql_insert_id());<br /> ?&gt;<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(&#39;localhost:3306&#39;, $user, $password)<br /> or die(&quot;Could not connect: &quot; . mysql_error());<br /> mysql_select_db(&quot;database&quot;);<br /> $result = mysql_query(&quot;select * from table&quot;)<br /> or die(&quot;Query failed: &quot; . mysql_error());<br /> /* get column metadata */<br /> $i = 0;<br /> while ($i &lt; mysql_num_fields($result)) {<br /> echo &quot;Information for column $i:<br /> n&quot;;<br /> $meta = mysql_fetch_field($result);<br /> if (!$meta) {<br /> echo &quot;No information available<br /> n&quot;;<br /> }<br /> echo &quot;</p> <pre> blob: $meta-&gt;blob max_length: $meta-&gt;max_length multiple_key: $meta-&gt;multiple_key name: $meta-&gt;name not_null: $meta-&gt;not_null numeric: $meta-&gt;numeric primary_key: $meta-&gt;primary_key table: $meta-&gt;table type: $meta-&gt;type unique_key: $meta-&gt;unique_key unsigned: $meta-&gt;unsigned zerofill: $meta-&gt;zerofill </pre> <p>&quot;;<br /> $i++;<br /> }<br /> mysql_free_result($result);<br /> ?&gt;<br /> <br /> <br /> mysql_get_server_info<br /> mysql_get_server_info -- 取得 MySQL 服务器信息<br /> 例子 1. mysql_get_server_info() 例子<br /> <!--?php<br /--> mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;) or<br /> die(&quot;Could not connect: &quot; . mysql_error());<br /> printf (&quot;MySQL server version: %sn&quot;, mysql_get_server_info());<br /> ?&gt;<br /> <br /> strstr<br /> strstr -- Find first occurrence of a string<br /> 例子 1. strstr() example<br /> <!--?php<br /--> $email = &#39;user@example.com&#39;;<br /> $domain = strstr($email, &#39;@&#39;);<br /> echo $domain; // prints @example.com<br /> ?&gt;<br /> <br /> mysql_escape_string<br /> mysql_escape_string -- 转义一个字符串用于 mysql_query<br /> 例子 1. mysql_escape_string() 例子<br /> <!--?php<br /--> $item = &quot;Zak&#39;s Laptop&quot;;<br /> $escaped_item = mysql_escape_string($item);<br /> printf (&quot;Escaped string: %sn&quot;, $escaped_item);<br /> ?&gt;</p>
RangeTime:0.007117s
RangeMem:211.53 KB
返回顶部 留言