What functions does mysql use to execute mysql statements?

Source: Internet
Author: User
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 ();

}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.