mysqli_query()

$result_set=mysqli_query($connection,$query,MYSQLI_STORE_RESULT);
$result_set=$connection->($query,MYSQLI_STORE_RESULT)
$result_set is FALSE on failure , for SELECT ,SHOW or EXPLAIN we will get mysqli_result object. For other ( successful ) queries we get TRUE as return value.

$query is the query string
resultmode : MYSQLI_USE_RESULT ( default ) or MYSQLI_STORE_RESULT

MySQLI database connection file

Example : Object Oriented Style
<?Php
require "config.php";// Database connection file.

$query="select * from student LIMIT 0,5 ";
if ($result_set = $connection->query($query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['id'],$row['name'],$row['class'],$row['mark']."<br>";
}
 $result_set->close();
}
?>

MySQL SELECT Query

Query with Number of records using num_rows

<?Php
require "config.php";// Database connection file.

$query="select * from student ";
if ($result_set = $connection->query($query)) {
echo "Total No. of records :".$result_set->num_rows;
    $result_set->close();
}
?>
Procedural style
<?Php
require "config.php";// Database connection file.

$query="select * from student LIMIT 0,5 ";
if ($result_set = mysqli_query($connection,$query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['id'],$row['name'],$row['class'],$row['mark']."<br>";
}
 $result_set->close();
}?>

MySQL DUMP of student table

Checking if matching record is available

$t="SELECT * FROM istudent where mark >90";

$check=$connection->query($t);
if(mysqli_num_rows($check)>0){
// record found 	
}else{
// No record found 	
}

Updating records with error message

$query="UPDATE  student SET class='Five'";
if ($connection->query($query)) {
echo "Records Updated";
}else{
echo $connection->error;
}
Your Rating





Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer