PHP MySql Select

PHP Have Query Method for all types of SQL Operations.

MySQL Select (Object Oriented)


<?php

$server="localhost";
$username="root";
$password="";
$db="e-commerce";

$conn=new mysqli($server,$username,$password,$db);

if($conn->connect_error){
	die("Error:".$conn->connect_error);
}

$SelectQuery="SELECT FirstName,LastName,PhoneNumber FROM Customers";
 
$result=$conn->query($SelectQuery);
if($result->num_rows>0){
	//Output
	while($row=$result->fetch_assoc()){
		echo 'First Name:'.$row['FirstName'].'Last Name:'.$row['LastName'].'Phone#'.$row['PhoneNumber']."<br />";
	}
}else{
	echo 'No Record Found.';
}

$conn->close();
?>

MySQL Select (Procedural)


<?php

$server="localhost";
$username="root";
$password="";
$db="e-commerce";

$conn=mysqli_connect($server,$username,$password,$db);

if(!$conn){
	die("Error:".mysqli_connect_error());
}

$SelectQuery="SELECT FirstName,LastName,PhoneNumber FROM Customers";
 
$result=mysqli_query($conn,$SelectQuery);
if(mysqli_num_rows($result)>0){
	//Output
	while($row=mysqli_fetch_assoc($result)){
		echo 'First Name:'.$row['FirstName'].'Last Name:'.$row['LastName'].'Phone#'.$row['PhoneNumber']."<br />";
	}
}else{
	echo 'Erro:'.mysql_error($conn);
}

mysqli_close($conn);
?>