Created
May 20, 2017 05:00
-
-
Save arsho/a203e7bc156ea566587361a76038f020 to your computer and use it in GitHub Desktop.
Like operator in PDO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thankyou very much. It really helps me.