Return Value of mysql_query
<? Php
$ 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:
<? Php
$ 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 ();
}
?>
The mysql_query () function executes a query on a MySQL database.
The function of mysql_query () is used to send a MySQL query.
This function returns the query handle for SELECT queries, TRUE/FALSE for other
Queries, or FALSE on failure.
If the function is successfully executed, True is returned and the query result is returned using the SELECT query statement. If the function is executed
Failed. False is returned.
Syntax
Syntax
Mysql_query (query, connection)
Parameter Description
Query Required. Specifies the SQL query to send (shocould not end with
Semicolon)
Required parameter. Specify the SQL query statement to be sent (it cannot end with a semicolon)
Connection Optional. Specifies the MySQL connection. If not specified, the last
Connection opened by mysql_connect () or mysql_pconnect () is used.
Optional. Specify the MySQL connection. If this parameter is not specified, the mysql_connect () function is used by default.
Or the last opened connection of the mysql_pconnect () function