PDO Database connection (Simple Select Method)

<?php
$servername = "localhost";
$username = "username";
$password = "password";

try {
  $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);


  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

 echo "Connected successfully";

catch(PDOException $e) 

{
  echo "Connection failed: " . $e->getMessage();
}
?>


//Sql Statement With Simple Select

$sql= $conn->simple_select("TABLE_NAME", "COLUMN_NAME", "WHERE_STATEMENT");


//it select two column where sid is $sid
$sql= $conn->simple_select("settings", "column1,column2", "sid={$sid}");

//it select two column where sid is 15
$sql= $conn->simple_select("settings", "column1,column2", "sid=15");

//it select all data (*) where sid is $sid
$sql= $conn->simple_select("settings", '*', "sid={$sid}");


//While Statement

while($row = $conn->fetch_array($sql))
{
$variable_name = $row['column_name'];
}


//Close Connection
$conn = null;

Post a Comment

0 Comments