<?php
$localhost ="localhost";
$username = "root";
$password = "";
$dbname = "sbnhs";
try {
$db = new PDO("mysql:host=$localhost;dbname:$dbname", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// echo "Success";
$x = 0128;
$sql = $db->prepare("SELECT * FROM $dbname.refcitymun WHERE provCode = :provcode");
$sql->bindValue(':provcode', $x);
if($sql->execute()) {
while($result = $sql->fetch()){
$desc = $result['citymunDesc'];
echo $desc;
}
}else {
echo 'Query Error';
}
}catch (PDOException $e) {
print 'Error: ' . $e->getMessage() . '</br>';
die();
}
?>
I want to display the data in my address column but it does not display anything nor error. I dont know what is wrong with the code
<?php
$localhost ="localhost";
$username = "root";
$password = "";
$dbname = "sbnhs";
try {
$db = new PDO("mysql:host=$localhost;dbname:$dbname", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// echo "Success";
// $x = 0128;
$sql = $db->prepare("SELECT * FROM $dbname.refcitymun WHERE provCode = 0128");
// $sql->bindValue(':provcode', $x);
if($sql->execute()) {
while($result = $sql->fetch()){
$desc = $result['citymunDesc'];
echo $desc;
}
}else {
echo 'Query Error';
}
}catch (PDOException $e) {
print 'Error: ' . $e->getMessage() . '</br>';
die();
}
?>
But when i try the format above it display the data that i want. But i need to use variable in the statement. Please check what is wrong with the first code