mysql_query
Send a MySQL query.
Function: mysql_query()
Applicable version: PHP 5.x - PHP 7.0.x (excluding PHP 7.0.x)
Usage: The mysql_query() function is used to send queries or execute statements to a MySQL database.
Syntax: resource mysql_query ( string $query [, resource $link_identifier = NULL ] )
parameter:
Return value: Returns a resource identifier (for subsequent operations) when successful, and returns FALSE when failure.
Notes:
Example:
// 连接到MySQL 数据库$link = mysql_connect("localhost", "username", "password"); if (!$link) { die('连接失败: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db("database_name", $link); if (!$db_selected) { die('选择数据库失败: ' . mysql_error()); } // 执行查询$result = mysql_query("SELECT * FROM users"); if ($result) { // 获取结果集中的数据while ($row = mysql_fetch_assoc($result)) { echo "ID: " . $row['id'] . ", 名字: " . $row['name']; } } else { echo "查询失败: " . mysql_error(); } // 关闭连接mysql_close($link);
Note that since the mysql_query() function has been deprecated, it is recommended to use the mysqli or PDO_MySQL extension to connect to and manipulate the MySQL database. The above examples are for reference only and are not recommended for use in production environments.