Hello,
I have started learning php and mysql recently, and I have run into problems. I received this code: *
Parse error: syntax error, unexpected 'average_user' (T_STRING)* and the problem is that I granted SELECT to average_user in the databse, but it is coming up with an error. What is with it? The code looked like this : <?php $dsn= 'mysql :host=localhost; dbname=my_store"; $username='average_user'; $password='password'; try{ $db=new PDO ($dsn,$username,$password)} catch (PDOexception $e){$error_message=$e->get_message(); include (database_error.php); exit();}?>
Anything stick out? Thanks

Member Avatar
LastMitch

@vivosmith

Parse error: syntax error, unexpected 'average_user' (T_STRING)* and the problem is that I granted SELECT to average_user in the databse, but it is coming up with an error. What is with it?

<?php 
$dsn= 'mysql:host=localhost; 
dbname=my_store"; 
$username='average_user'; 
$password='password'; 
try{ $db=new PDO ($dsn,$username,$password)} 
catch (PDOexception $e){$error_message=$e->get_message();include (database_error.php); exit();}
?>

On your first line:

$dsn= 'mysql:host=localhost;

you are missing a qoute at the end '

It should be this:

$dsn= 'mysql:host=localhost';

Please read this if you are using PDO.

http://www.daniweb.com/web-development/php/code/435142/using-phppdo-with-error-checking

It's a nice tutorial about PDO. Much more organized.

Line 2 and 3 belong together:

$dsn = 'mysql:host=localhost;dbname=my_store';

So because average_user is connected to localhost, and localhost is not registered properly, it won't show up?

The error indicated that the string was not terminated correctly. It has nothing to do with the actual user in MySQL.

Ok, so it was a sytax error then since not everything was formatted?

Thank, I appreciate the help :)