-
-
- $DB_HOST ="localhost";
- $DB_LOGIN ="root";
- $DB_PASSWORD =" 123456";
- $conn=mysql_connect($DB_HOST,$DB_LOGIN,$DB_PASSWORD);
Copy code
mysql_data_seek
Move the inner query pointer to the query row
grammar
bool mysql_data_seek(resource result_indetifier,int row_number)
Example:
-
-
- $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);//Move the pointer back to the first row of the query result
Copy code
mysql_fetch_array
Store the query results in an array (each array element stores a record)
grammar
array mysql_fetch_array(resource result[,int result_type])
Example:
-
-
- $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);
Copy code
mysql_fetch _object
Obtain a row of query results and store it as an object type. The usage method is exactly the same as MySQL_fetch_array(). The difference is that mysql_fetch_object() can only obtain query results through field names.
echo $row->fieldname; //Correct usage
echo $row->0; //wrong usage
grammar
object mysql_fetch_object(resource result)
Example:
-
-
- $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;
- }
Copy code
mysql_insert_id
After using the INSERT command to add a piece of information, you can use this function to obtain the unique id of the record just added.
grammar
int mysql_insert_id([esource link_identifier])
Example:
-
-
- $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 book')";
- $res=mysql_query($res);
- $p_id=mysql_insert_id();
Copy code
mysql_num_rows
Get how many rows there are in the query results
grammar
int mysql_num_rows(resource result)
Example:
-
-
- $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);
Copy code
mysql_query
Send a SQL syntax query statement
grammar
resource mysql_query(string query[,resource link_identifier])
Example:
-
-
- $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");
Copy code
mysql_select_db
Select the name of the database you want to access
grammar
bool mysql_select_db(string database_name[,resource link_identifier])
Example:
-
-
- $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);
Copy code
1 2 3 Next page Last page
|