CHAPTER 6 – Mysql Queries
This section describes functions and methods for executing queries see Table 6.3). Table 6.3 mysqli Query Functions Function Name Description mysqli_query(...) Sends a query to the database and returns a result object. Parameters: · connection (function only) · query (string) · mode (buffered or unbuffered) mysqli_multi_query(...) Sends and processes multiple queries at $mysqli->multi_query(...) once. Parameters: · connection object (function only) · query (string) The mysqli_query() function returns a result set object. On failure, use the mysqli_error() function or the $conn->error property to determine the cause of the failure: <?php $conn = mysqli_connect("localhost", "test", "", "world"); $result = $conn->query("SELECT Name FROM City"); while ($row = $result->fetch_row()) { print $row[0] . "<br>n"; } $result->free(); $conn->close(); After the query has been executed, memory on the client side is allocated to retrieve the complete result set. To use unbuffered resultset, you have to specify the optional parameter MYSQLI_USE_RESULT: <?php $conn = mysqli_connect("localhost", "test", "", "world"); $result = $conn->query("SELECT Name FROM City", MYSQLI_USE_RESULT); while ($row = $result->fetch_row()) { print $row[0] . "<br>n"; } $result->free(); $conn->close();