For this code:
$title = '0';
$subTitle = '1';
$tableName = 'someString';
$stmt = $dbh->prepare("SELECT `".$title."`, `".$subTitle."` FROM `".$tableName."_data` WHERE `id` = :key");
$stmt->bindValue(':key', '127');
$stmt->execute();
$result = $stmt->fetchAll();
print_r($result);
I get $result as this:
Array
(
[0] => Array
(
[0] => 91651
[1] => 91651 - DESCRIPTION
[2] => 91651 - DESCRIPTION
)
)
When the expected result should be this:
Array
(
[0] => Array
(
[0] => 91651
[1] => 91651 - DESCRIPTION
)
)
When I run the same query in mySQL, it returns the expected result. When it is executed via PHP PDO, it adds a duplicate.
Thanks!
Use fetchAll(PDO::FETCH_ASSOC) instead of fetchAll().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With