PHP mysqli_query() Function

PHP mysqli_query() function is used to performs a query on the database.

Syntax

mixed mysqli_query(connection,query,resultmode);

mysqli_query() Function Parameter

ParameterDescription
connection :Required parameter. The MySQL connection to be used
query :Required parameter. The query string
resultmode :Optional parameter. Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

mysqli_query() Function Return Value

Return Values :Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object.

mysqli_query() Function Example

<?php
$con = mysqli_connect("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Perform queries 
mysqli_query($con,"SELECT * FROM employee");
mysqli_query($con,"INSERT INTO employee (fname,lname,designation) VALUES ('Michael','M','Manager')");

mysqli_close($con);
?>