ronc0011 Posted September 5, 2017 Share Posted September 5, 2017 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 More sharing options...
ronc0011 Posted September 5, 2017 Author Share Posted September 5, 2017 OK never mind I finally spotted what the problem was . The variable "conn" didn't have the right syntax. It should have been "$conn" Fixed it instantly. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.