Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

MySQLi With Prepared Statements For Beginners

by
Category:php
php mysql
MySQLi With Prepared Statements For Beginners

Prepared statements may seem intimidating at first, but once you get hang of it, it’ll seem like second nature to you. The goal of this tutorial is to transform someone with little to no knowledge of prepared statements, into an expert. You may also like Mysql Database Connection in PHP.

Database Connection

<?php
    $db = new mysqli('host', 'UserName', 'Password', 'DatabaseName');
    if($db->connect_errno > 0)
    {
        die('Unable to connect to database [' . $db->connect_error . ']');
    }
?>

Select Query

$results = $db->query("SELECT id,name from emp");

Data fetch in Database

while($row = $result->fetch_assoc())
{
    echo $row['id'];
    echo $row['name'];
}

Now rows Count

<?php
echo 'Total results: ' . $result->num_rows;
?>

0 Comments


Html code work in comment box


Related Post