Jump to content

Is there something fundamentally wrong with PHP?


ronc0011

Recommended Posts

Honestly I’ve hit this wall more times than I can count. It typically turns out to be something seemingly arbitrary like single or double quotes and only maters sometimes and sometimes not.

OK enough with the ranting. Here is the code that is making me pull my hair out…

It’s a PDO connection string that I’m getting from a Youtube video.

$host = "127.0.0.1";
$user = "root";
$pass = "r00t";
$db = "cars";
try{
conn = new PDO ("mysql:host=$host;dbname=$db", "$user", "$pass");
conn -> setAttrabute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
echo "Oh happy day we have connected to our database";
} Catch (PDOException $e) {
die("Well, that didn't work at all");
}

It’s giving me this error…

Parse error: syntax error, unexpected '=' in C:\Apache24\htdocs\PDO\conn.php on line 10

Line 10 is the line with the new PDO.

 

I’ve been staring at the example code and comparing it to my code till my eyes are about to cross and I can’t find what it is that’s causing the problem.

I’ve tried it with double quotes as well as single quotes. No help. I only say that because it’s been an issue on other occasions

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.