Bind Param To SQL Statement

Submitted by:Jhon Jhon

Date added:16 February, 2013

Category:PHP

Binds a php variable to an SQL statement using the bindParam() method

Tags: bind param

Code Snippet:

<?php
$dbname = "";
$user = "";
$pass = "";

try{
$id = '9';
$pdo = new PDO("mysql:dbname=$dbname", $user, $pass);

$stm = $pdo->prepare("SELECT * FROM [YOUR_TABLE_HERE] WHERE id=:id");
$stm->bindParam(':id', $id);
$stm->execute();
$result = $stm->fetchAll(PDO::FETCH_ASSOC);
print_r($result);

}catch ( PDOException $e ){
echo $e->getMessage();
}
?>
 
 

Comments