What functions does mysql use to execute mysql statement definitions and usage? The mysql_query () function executes a MySQL query. The mysql_query (query, connection) parameter description is required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon. Connection
What functions does mysql use to execute mysql statement definitions and usage? The mysql_query () function executes a MySQL query. The mysql_query (query, connection) parameter description is required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon. Connection
What functions does mysql use to execute mysql statements?
Definition and usage
The mysql_query () function executes a MySQL query.
Syntax
Mysql_query (query, connection) parameter description
Query is required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon.
Connection is optional. Specifies the SQL connection identifier. If not specified, the last opened connection is used.
Description
If no connection is enabled, this function will try to call the mysql_connect () function without parameters to establish a connection and use it.
Return Value
Mysql_query () Only returns a resource identifier for SELECT, SHOW, EXPLAIN or DESCRIBE statements. If the query execution is incorrect, FALSE is returned.
For other types of SQL statements, if mysql_query () is executed successfully, TRUE is returned. If an error occurs, FALSE is returned.
If the return value is not FALSE, the query is legal and can be executed by the server. This does not indicate any affected or returned number of rows. It is very likely that a query is successfully executed but does not affect or no rows are returned.
Tips and comments
Note: This function automatically reads and caches record sets. To run a non-Cache query, use mysql_unbuffered_query ().
Example 1
$ Con = mysql_connect ("localhost", "mysql_user", "mysql_pwd ");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
$ SQL = "SELECT * FROM Person ";
Mysql_query ($ SQL, $ con );
// Some code
Mysql_close ($ con );
?>
Example 2
Use the mysql_query () function to create a new database:
$ Con = mysql_connect ("localhost", "mysql_user", "mysql_pwd ");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
$ SQL = "CREATE DATABASE my_db ";
If (mysql_query ($ SQL, $ con ))
{
Echo "Database my_db created ";
}
Else
{
Echo "Error creating database:". mysql_error ();
}
?>