I receive the following error…
Parse error: syntax error, unexpected T_AS in ….\index.php on line 98
for the following script…
<?php
try {
$db = new PDO('mysql:host=localhost;dbname=db', 'user', 'pw');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->beginTransaction();
$stmt = $db->prepare("SELECT * FROM tablename");
$stmt->execute();
while($db->fetch(PDO_FETCH_ASSOC) as $row) {
$id= $row['id'];
$name= $row['name'];
}
$db->commit();
}
catch (PDOException $e)
{
$db->rollback();
echo "There was a system error.<br>".$e->getMessage();
}
?>
Any idea what is throwing the error? I have checked for missing semicolons, commas, and the works but got nothing!
T_ASis the token forasin the PHP interpreter. It was unexpected when trying to parse your code’s syntax.asis only valid in aforeachloop, and you are using awhile.Change your
whileloop to aforeachloop.Update
This is a run time error – the PDO object has no method called
fetch(). Are you callingfetch()on the right object?Check out the documentation.
As Wrikken states in the comments, it will be a method of your
$stmtobject.