I have a problem with the PDO::FETCH_OBJECT
argument. I want to fetch an object and not an array, but when I try this:
try {
$conn = new PDO('mysql:host=localhost;dbname=washngo', $config['DB_USERNAME'], $config['DB_PASSWORD']);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Fetch errors by default ( display any errors during the development process )
$stmt = $conn->prepare('SELECT * FROM news');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_OBJECT)) { //By default, it fetch an array. The "PDO::FETCH_OBJECT" argument allows us to fetch an object
print_r($row);
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
I get
Fatal error: Undefined class constant '
FETCH_OBJECT
' in index.php on line 18.
When I try to let the fetch()
by default (without PDO::FETCH_OBJECT()
), it works fine.
Correct is not PDO::FETCH_OBJECT
but PDO::FETCH_OBJ
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