i have been trying to get some data out of a mysql database using php's pdo but its not outputting any data at all, i know PDO is installed and working because i have run other query's fine. here is my code
<?php
error_reporting(-1);
$db_host="localhost";
$db_username="mike16889";
$db_password="********";
$db_name="omni";
try {
$dbh = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_password);
}
catch(PDOException $e)
{
echo $e->getMessage();
};
try {
$sql = $dbh->("SELECT * FROM jobdetails");
$sql->bindParam(1, $_SESSION["workerID"]);
$sql->execute();
} catch(PDOException $e) {
echo $e->getMessage();
};
$sql->setFetchMode(PDO::FETCH_ASSOC);
while($row = $sql->fetchObject()){
print_r($row);
echo'</ hr>';
}
print_r($data);
?>
it outputs absolutely nothing, no errors and no data.
Why are you suppressing errors while in development?
$sql = $dbh->("SELECT * FROM jobdetails"); //dbh-> what? any method name missing? guess
Should be
$sql = $dbh->prepare("SELECT * FROM jobdetails");
^
您忘了在下面的行中写prepare
$sql = $dbh->prepare("SELECT * FROM jobdetails");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.