Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion Using PHP with MySQL Connecting PHP to MySQL Handling Exceptions

Edmunds Sulzanoks
Edmunds Sulzanoks
5,828 Points

MySQL Improved Extension

So my hosting provider uses cPanel and I couldn't find a mySQL port number. But whle trying to find it I saw this in mysql server info tab "PHP extension: mysqli". After checking it out I found out that it stands for "MySQL Improved Extension" (wierd abbreviation) and that I should open DB connection like this:

$db=mysqli_connect('localhost','db_name','password','username');

seems a more efficient way. Is this something all recent mysql versions support or do you need to have a special "PHP extention" installed?

1 Answer

Edmunds Sulzanoks
Edmunds Sulzanoks
5,828 Points

Found answer.

The core advantage of PDO over MySQLi is in its database driver support. At the time of this writing, PDO supports 12 different drivers, opposed to MySQLi, which supports MySQL only. In situations when you have to switch your project to use another database, PDO makes the process transparent. So all you'll have to do is change the connection string and a few queries - if they use any methods which aren't supported by your new database. With MySQLi, you will need to rewrite every chunk of code - queries included.