Return Value of mysql_query

Source: Internet
Author: User

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

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.