The mysqli real_query function is a PHP function that sends a SQL query to the MySQL database. It is an extension of the mysqli extension that provides an object-oriented interface to MySQL database. The real_query function performs a query against the database and returns the result set in a buffered or unbuffered manner.
Example 1: Sending a SELECT query using mysqli real_query
$mysqli = new mysqli('localhost', 'user', 'password', 'database'); $query = "SELECT * FROM employees WHERE age > 30"; if ($mysqli->real_query($query)) { $result = $mysqli->store_result(); while ($row = $result->fetch_assoc()) { echo $row['name'] . " | " . $row['age'] . " "; } } $mysqli->close(); ?>
This example sends a SELECT query to the employees table, selects all rows where the age field is greater than 30. The mysqli real_query function is used to send the query to the database server. If the query is successful, the mysqli store_result function is used to retrieve the result set. The while loop then iterates through the rows and prints the name and age of each employee.
Example 2: Sending an INSERT query using mysqli real_query
This example sends an INSERT query to the employees table, inserting a new employee called John Doe with an age of 35 and a salary of 55000. The mysqli real_query function is used to send the query to the database server. If the query is successful, the message "New employee added!" is displayed. If there is any error, the message "Error: " along with the error message is displayed.
The above examples use the mysqli extension library package.
PHP mysqli::real_query - 17 examples found. These are the top rated real world PHP examples of mysqli::real_query extracted from open source projects. You can rate examples to help us improve the quality of examples.