Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use mysql_query () in php

Shulou Source: shulou.com Published: 2022-06-03 13:49:53 10月20日 Update

This article will explain in detail how to use mysql_query () in php. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The php mysql_query () function is used to execute the sql statement. When querying, updating, and adding data, you can write the sql statement, and then use the mysql_query () function to execute the sql statement to operate on the specified database; syntax "mysql_query ($sql [, $con])".

Operating environment of this tutorial: windows7 system, PHP5 version, DELL G3 computer

The php mysql_query function is used to execute sql statements. For example, when querying, updating, and adding data, we usually write sql statements, and then use mysql_query to perform the operations required by sql.

Let's take a look at an example:

The steps for php to manipulate the database can be divided into the following steps:

1. Connect to the database server

2. Select the database to be operated

3. Execute the SQL statement

4. The result set obtained by processing the SQL statement

5. Shut down or disconnect the database server

The third step in executing the sql statement requires the use of the mysql_query () function, as shown in the above example:

$query = "drop table if exists mytable"; $result = mysql_query ($query)

This SQL statement executes the command to delete the table mytable. Returns true if the execution is successful, false otherwise. But the mysql_query function does not necessarily just return true and false.

The mysql_query function returns a resource identifier for SELECT, SHOW, EXPLAIN, or DESCRIBE statements, or FALSE if the query executes incorrectly. For other types of SQL statements, mysql_query () returns TRUE on success and FALSE on error.

Note:

Mysql_query () has been deprecated since PHP 5.5.0 and removed since PHP 7.0.0. It should be replaced with a MySQLi or PDO_MySQL extension. To replace this function are:

Mysqli_query ()

PDO::query ()

This is the end of the article on "how to use mysql_query () in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Statements functions data databases articles queries success examples more servers steps updates services good practical content commands tutorials articles logos Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Docker Xiaomi Shulou Technology