English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_real_query() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_real_query() function executes a mysql query

Definition and Usage

mysqli_real_query()The function executes a single database query, whose results can be retrieved or stored using mysqli_store_result() or mysqli_use_result().
To determine whether the given query really returns a result set, you can check mysqli_field_count().

Syntax

mysqli_real_query($con, $query)

Parameter

Serial NumberParameters and Description
1

con(Required)

This is an object representing the connection to the MySQL Server.

2

query(Required)

This is a string value representing the query to be executed. The data passed to this query should be properly escaped.

Return Value

The query returns a boolean value,IfIf successful, thentrue; If it fails, thenfalse.

PHP Version

This function was originally introduced in PHP version5introduced and can be used in all higher versions.

Online Example

The following examples demonstratemysqli_real_query()Function Usage (Procedural Style)-

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE IF NOT EXISTS my_team(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
   print("Create table ..."."\n");
   //Insert records into the my_team table
   mysqli_real_query($con, "insert into my_team values(")1, 'Shikhar', 'Dhawan', 'Delhi', 'India')");
   mysqli_real_query($con, "insert into my_team values(")2, 'Jonathan', 'Trott', 'Cape Town', 'South Africa')");
   mysqli_real_query($con, "insert into my_team values(")3, 'Kumara', 'Sangakkara', 'Matale', 'Sri Lanka')");
   mysqli_real_query($con, "insert into my_team values(")4, 'Virat', 'Kohli', 'Delhi', 'India')");
   print("Insert record ..."."\n");
   //Close connection
   mysqli_close($con);
?>

Output results

Create table ...
Insert record ...

Online Example

In the object-oriented style, the syntax of this function is$con-> real_query();.Here is an example of this function in an object-oriented style;

<?php
   $con = new mysqli("localhost", "root", "password", "mydb");
   //Insert a record into the players table
   $con-> query("CREATE TABLE IF NOT EXISTS players(First_Name VARCHAR(255), Last_Name VARCHAR(255), Country VARCHAR(255))");
   $con-> real_query("insert into players values('Shikhar', 'Dhawan', 'India')");
   $con-> real_query("insert into players values('Jonathan', 'Trott', 'South Africa')");
   print("Data creation......");
   //Close connection
   $res = $con -> close();
?>

Output results

Data creation......

PHP MySQLi Reference Manual