Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKnowledgeWoods Consulting
5,607 PointsCould not connect to Database.
I am not able to connect through this PDO. But i my database is connected when i used mysql_connect. What is the difference between these two and why i am not able to connect to DB?
4 Answers
Kennard McGill
Full Stack JavaScript Techdegree Graduate 43,179 PointsYou should post the code you are using to connect to the DB so someone can help you troubleshoot your code.
For reference here's a good article on why you might want to use PDO PHP Data objects. Why use PDO?
KnowledgeWoods Consulting
5,607 PointsI have read that but it will be of great help if you could tell me the difference between mysql_connect and PDO ?
Kennard McGill
Full Stack JavaScript Techdegree Graduate 43,179 PointsYou shouldn't use mysql_connect anymore for security reasons (sql injections). It's also been deprecated You should look at mysqli_* if you are more comfortable with using the old mysql_ statements
PDO allows you to connect to different database with one single interface as well as provide a bunch of other methods for working with data. Just need to check out the documentation for more info.
Leonardo Hernandez
13,798 PointsIt is my understanding that PDO is a built in class, and mysql_connect is a built in function. It is also my understanding that one would create a class and use mysql_connect as methods. PDO is already a class so a lot of work has been programmed for us.
As for you connection, lets see the code !