What functions does MySQL use to execute MySQL statements
Definitions and usage
The mysql_query () function executes a MySQL query.
Grammar
mysql_query (query,connection) parameter description
Query required. Specify the SQL query to send. Note: The query string should not end with a semicolon.
Connection optional. Specify the SQL connection identifier. If not specified, the previous open connection is used.
Description
If there is no open connection, this function attempts to call the mysql_connect () function without arguments to establish a connection and use it.
return value
mysql_query () returns a resource identifier only for the Select,show,explain or DESCRIBE statement and FALSE if the query executes incorrectly.
For other types of SQL statements, mysql_query () returns TRUE on successful execution, and returns FALSE when an error occurs.
A return value other than FALSE means that the query is legitimate and can be executed by the server. This does not indicate any number of rows that are affected or returned. It is quite possible that a query execution succeeded but did not affect or return any rows.
Tips and comments
Note: This function automatically reads and caches the recordset. Use Mysql_unbuffered_query () if you want to run a non-cached 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
To create a new database by using the mysql_query () function:
$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 ();
}
?>