-1

I am performing a SELECT but nothing is output despite there being valid data in the db table. Help please:

I have error checked everywhere I can and I get no errors, but I also get no output. The code:

<?php

/*** mysql hostname ***/
$hostname = 'removed';
$dbname = 'removed';
/*** mysql username ***/
$username = 'removed';
/*** mysql password ***/
$password = 'removed';
function testdb_connect ($hostname, $username, $password){
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
return $dbh;
}

try {
$dbh = testdb_connect ($hostname, $username, $password);
echo 'Connected to database';
} catch(PDOException $e) {
echo $e->getMessage();
}
$dbh = testdb_connect ($hostname, $username, $password);

$id=3;
echo 'dfsdfs '.$id.' <p>';
var_dump($dbh);
$sql="SELECT * FROM removeddbname.weblog_article WHERE 'id' = :id";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':id', $id);
$stmt->execute();
if (!$stmt) {
  echo "\nPDO::errorInfo():\n";
  print_r($dbh->errorInfo());
}
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {  
echo "Performing a select: <br>";
print_r($row);                                  
echo ' ddddddddddddddddddddd '. $row['title'];
echo 'd ddddddddd'. $row['desc']; 
}
// close the PDO connection
$link = null;
?>

The output for the above code is:

Connected to databasedfsdfs 3 object(PDO)#2 (0) { }

Can someone please help? Not sure what to do here as I get no errors and no output...

bobafart
  • 173
  • 2
  • 2
  • 11

1 Answers1

0

Remove the single quotes enclosed for id

SELECT * FROM removeddbname.weblog_article WHERE id = :id

Tamil
  • 1,193
  • 9
  • 24