The commonly used mysqli methods are as follows
mysqli_connect
: Connection authentication
mysqli_connect_error
: Error message of connection failure
mysqli_close
: Close the connection
mysqli_errno
: Error number
mysqli_error
: Error message
mysqli_query
: Execute query SQL command
mysqli_affected_rows
: The current mysql operation is affected The number of rows (write operation)
mysqli_num_rows
: The number of rows in the current query result set
mysqli_free_result
: Release the result set of the query
mysqli_fetch_row
: Retrieve a record from the query result set and return a one-dimensional array (index array)
mysqli_fetch_assoc
: Retrieve a record from the query result set and return As an array (associative array: field name as subscript)
mysqli_fetch_all
: Fetch all records from the query result set and return a two-dimensional array
PHP connects to MySQL Summary of native MySQL functions
1. Configure connection database information
1. Connect to databasemysql_connect($server, $username, $password)
2. Set the character set mysql_set_charset($charset)
3. Select the database mysql_select_db($database_name)
2. Send and execute the sql statement to the database
mysql_query($sql); If the sql statement fails to be executed, false will be returned. If the execution is successful, it will be returned if there are resources (execution of queries, etc.) resources, the rest returns true.
3. Parse data from the returned result set
1. Return the number of affected rows
mysql_num_rows ($result)
Get the number of rows in the result set
mysql_affected_rows()
Get the number of record rows affected by the previous operation
mysql_insert_id()
; Obtain the ID generated by the previous insertion operation
2. Return the query resource (the following is to obtain one row of records from the result set at a time)
mysql_fetch_row()
Numeric index
mysql_fetch_assoc()
Field name index
mysql_fetch_array()
Both
3. Return the error message
mysql_error()
; Text error message
mysql_errno()
; Error Digital encoding of information
4. Close the database connection
mysql_close()
;
PDO in PHP Function library
1. PDO
##PDO->beginTransaction() — Mark the rollback starting point
PDO->commit() — Mark the rollback end point and execute SQL
PDO->__construct() — Establish a PDO link database Example
PDO->errorCode() — Get the error code
PDO->errorInfo() — Get the error information
PDO->exec() — Process a SQL statement and return the number of entries affected
PDO->getAttribute() — Get the properties of a "Database Connection Object"
PDO->getAvailableDrivers() — Get the valid PDO driver name
PDO->lastInsertId( ) —Get the primary key value of the last piece of data written
PDO->prepare() —Generate a "query object"
PDO->query() — Process a SQL statement and return a "PDOStatement"
PDO->quote() — A character in a certain SQL Add quotes to the string
PDO->rollBack() — Perform a rollback
PDO->setAttribute() — For a "database "Connection object" setting properties
The above is the detailed content of What are the functions for linking php to mysql?. For more information, please follow other related articles on the PHP Chinese website!