i try to learn PHP OOP, just try to make simple script which print down all users from database, my code looks like:
<?php
/* start config */
define( "DB_HOST", "mysql:host=localhost;dbname=test" );
define( "DB_USER", "root" );
define( "DB_PASS", "" );
/* end config */
try{
$connection = new PDO("DB_HOST","DB_USER","DB_PASS");
$connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM users";
$stmt = $connection->prepare( $sql );
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
while( $row = $stmt->fetch()) {
echo $row['user'];
}
}catch{
(PDOExeption $e);{
echo $e->getMessage();
}
}
?>
I try to follow the example code and in my eyes code looks good but it throw this error: Parse error: syntax error, unexpected '{', expecting '(' in D:\xampp\htdocs\xampp\oop\andurit.php on line 18
Why? i am pretty sure that { have to be here to start that catch so WHY its not working, i hope for some explain what i am doing wrong :)
thanks you all