Execute a query against the database:
Delete database
<?php
// 假定数据库用户名:root,密码:123456,数据库:RUNOOB
$con=mysqli_connect("localhost","root","123456","RUNOOB");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 执行查询
mysqli_query($con,"SELECT * FROM websites");
mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES ('百度','https://www.baidu.com/','4','CN')");
mysqli_close($con);
?>Definition and usage
The mysqli_query() function executes a query against the database.
Grammar
mysqli_query(connection,query,resultmode);
Parameter Description
connection required. Specifies the MySQL connection to use.
query Required, specifies the query string.
resultmode
Optional. a constant. Can be any of the following values:
MYSQLI_USE_RESULT(如果需要检索大量数据,请使用这个)
MYSQLI_STORE_RESULT(默认)
technical details
Return value: For a successful SELECT, SHOW, DESCRIBE, or EXPLAIN query, a mysqli_result object is returned. For other successful queries, TRUE will be returned. On failure, returns FALSE.
PHP version: 5+
Change log: Asynchronous query functionality is added in PHP 5.3.0.