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 trial

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

Edmunds Sulzanoks
Edmunds Sulzanoks
6,298 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
6,298 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.