Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What function does mysql use to execute mysql statements?
What function does mysql use to execute mysql statements?
What function does mysql use to execute mysql statement definition and usage mysql_query () function executes a mysql query. The syntax mysql_query(query, connection) parameter indicates that the query is necessary. Specify the SQL query to send. Note: The query string should not end with a semicolon. The connection can

What function does mysql use to execute mysql statements?

Definition and usage

Function executes a mysql query.

grammar

Parameter description of mysql_query (query, connection)

Queries are required. Specify the SQL query to send. Note: The query string should not end with a semicolon.

The connection is optional. Specifies the SQL connection identifier. If not specified, the last open connection is used.

explain

If there is no open connection, this function will try to call mysql_connect () function with no parameters to establish a connection and use.

Return value

Mysql_query () only returns the resource identifier of the SELECT, SHOW, EXPLAIN or DESCRIBE statement, and returns FALSE if the query is executed incorrectly.

For other types of SQL statements, mysql_query () returns TRUE on successful execution and FALSE on error.

Non-FALSE returning false means that the query is legal and can be executed by the server. This does not indicate the number of rows affected or returned. It is likely that a query was successfully executed, but no rows were affected or returned.

Tips and comments

Note: This function automatically reads and caches the recordset. To run an uncached query, use mysql_unbuffered_query ().

Example 1

$con = mysql_connect("localhost "," mysql_user "," MySQL _ pwd ");

If (! $con)

{

Die ('Unable to connect:'. MySQL _ error());

}

$ sql = " SELECT * FROM Person

mysql_query($sql,$ con);

//some code

MySQL _ close($ con);

& gt

Example 2

Create a new database through the mysql_query () function:

$con = mysql_connect("localhost "," mysql_user "," MySQL _ pwd ");

If (! $con)

{

Die ('Unable to connect:'. MySQL _ error());

}

$sql = "Create database my _ db ";;

if (mysql_query($sql,$con))

{

Echo "database my_db has been created";

}

other

{

Echo "Error creating database:". MySQL _ error();

}

& gt