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

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
queryRequired.Query string
resultmodeOptional.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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions