Home > Article > Backend Development > mysqli_query failed in php
PHP mysqli_query() function
Definition and usage (Recommended learning: PHP video tutorial)
mysqli_query() function executes a query against the database.
Syntax
mysqli_query(connection,query,resultmode);<br/>
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 (use this if you need to retrieve large amounts of data)
MYSQLI_STORE_RESULT (default)
Return value:
For a successful SELECT, SHOW, DESCRIBE or EXPLAIN query, a mysqli_result object will be returned. For other successful queries, TRUE will be returned. On failure, returns FALSE.
Execute a query against the database:
Delete database
<?php <br/>// 假定数据库用户名:root,密码:123456,数据库:RUNOOB <br/>$con=mysqli_connect("localhost","root","123456","RUNOOB"); <br/>if (mysqli_connect_errno($con)) <br/>{ <br/> echo "连接 MySQL 失败: " . mysqli_connect_error(); <br/>} <br/> <br/>// 执行查询<br/>mysqli_query($con,"SELECT * FROM websites");<br/>mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)<br/>VALUES ('百度','https://www.baidu.com/','4','CN')");<br/> <br/>mysqli_close($con);<br/>?><br/>
The above is the detailed content of mysqli_query failed in php. For more information, please follow other related articles on the PHP Chinese website!