-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD =" 123456";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
复制代码
mysql_data_seek
将内部查询指针移动至查询行上
语法
bool mysql_data_seek(resource result_indetifier,int row_number)
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $res=mysql_query("SELECT * FROM PRODUCT");
- $row=mysql_fetch_array($res);
- for($i=0;$i<$num;$i++)
- $row=mysql_fetch_array($res);
- mysql_data_seek($res,0);//移动指针回到查询果的第一行
复制代码
mysql_fetch_array
将查询的结果存在数组中(每一个数组元素存一个记录)
语法
array mysql_fetch_array(resource result[,int result_type])
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $res=mysql_query("SELECT * FROM PRODUCT");
- $row=mysql_fetch_array($res);
复制代码
mysql_fetch_object
取得查询结果一行,并以对象类型存储之,与MySQL_fetch_array()使用方法完全相同,不同的是mysql_fetch_object()只能通过字段名称来取得查询结果
echo $row->fieldname; //正确用法
echo $row->0; //错误用法
语法
object mysql_fetch_object(resource result)
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $res=mysql_query("SELECT * FROM PRODUCT");
- $row=$mysql_fetch_object($res);
- while($row)
- {
- echo $rowàp_id;
- echo $rowàp_name;
- }
复制代码
mysql_insert_id
在使用INSERT命令增加完一条信息后,可利用此函数取得刚刚增加记录的unique id
语法
int mysql_insert_id([esource link_identifier])
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $SQLStr"INSERT INTO produce (p_id,p_name)VALUES('','PHP书')";
- $res=mysql_query($res);
- $p_id=mysql_insert_id();
复制代码
mysql_num_rows
取得查询结果里有几行
语法
int mysql_num_rows(resource result)
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $res=mysql_query("SELECT * FROM PRODUCT");
- $num=mysql_num_rows($res);
复制代码
mysql_query
送出一个SQL语法的查询语句
语法
resource mysql_query(string query[,resource link_identifier])
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
- $res=mysql_query("SELECT * FROM PRODUCT");
复制代码
mysql_select_db
选择欲存取的数据库名称
语法
bool mysql_select_db(string database_name[,resource link_identifier])
示例:
-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD ="123456";
- $DB_NAME ="flag";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
- mysql_select_db($DB_NAME);
复制代码
1 2 3 下一页 尾页
|