Skip to content

Instantly share code, notes, and snippets.

@arsho
Created May 20, 2017 05:00
Show Gist options
  • Save arsho/a203e7bc156ea566587361a76038f020 to your computer and use it in GitHub Desktop.
Save arsho/a203e7bc156ea566587361a76038f020 to your computer and use it in GitHub Desktop.
Like operator in PDO
<?php
$user = "root";
$password = "";
$name = "%o%";
try{
$conn = new PDO('mysql:host=localhost;dbname=test_db',$user,$password);
$query = "SELECT * FROM `test_table` WHERE `name` like :name";
$stmt = $conn->prepare($query);
$stmt->bindParam(':name',$name);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$data = $stmt->fetchALl();
echo "<pre>";
var_dump($data);
echo "</pre>";
}
catch(PDOException $e){
echo "Error in PDO: ".$e->getMessage()."<br>";
die();
}
?>
@sumitpal2910
Copy link

thankyou very much. It really helps me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment