PHP mysqli_query() Function
Definition
The mysqli_query() function performs a query against the database.
Syntax
PHP mysqli_query() Function has the following syntax.
mysqli_query(connection,query,resultmode);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection to use |
query | Required. | Query string |
resultmode | Optional. | MYSQLI_STORE_RESULT (default) or MYSQLI_USE_RESULT (for large amount of data) |
For successful SELECT, SHOW, DESCRIBE, or EXPLAIN queries it will return a mysqli_result object.
For other successful queries it will return TRUE. FALSE on failure.
Return
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object.
For other successful queries mysqli_query() will return TRUE.
Example
<?php/* ww w . j av a 2s. co m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"SELECT * FROM emp");
mysqli_query($con,"INSERT INTO emp (name) VALUES ('PHP')");
mysqli_close($con);
?>