Connecting to database via PHP program?

How do I get my PHP programs to connect to the MySQL databases on the new system?

Both MySQL and PHP have been upgraded at least a version so I’m guessing that I’ll need to make some changes to get my code to work properly on the new system. This is the code I used to get connected on the old system, with my actual database name, user-id, and password replaced by , , and respectively:

<?php try { $db = new PDO('mysql:host=mysql6.000webhost.com;dbname=;charset=utf8', '', ''); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (PDOException $excp) { echo "Error getting database connection: " . $excp->getMessage(); } ?>

Do I simply replace mysql6.000webhost.com with databases.000webhost.com and then use my new database name, userid, and password or is there more that I need to do?

If you replace “mysql.000webhost.com” with “localhost”, it should work.

1 Like