There are three method for handling database in PHP 1. MySQLi- object-oriented 2. MySQLi - procedural -oriented 3. PDO - PHP Database Objec t First create variable required $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "sample_db"; Method 1 : - MySQLi - object-oriented Create connection : - $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } Fetch the records from table : - $sql = "SELECT * FROM users"; $result = $conn->query($sql); get rows count : - $count = $result->num_rows; iterate through records : - while($row = $result->fetch_assoc()) { //print single row details print_r($row); } close connection : - $conn->close(); Method 2 :- MySQLi - procedural -oriented Create connection $con...
Php Web Development Blog