I am receiving the following Error Message:
"There was an error connecting to the database.
Error message: could not find driver"
My GoDaddy package includes Linux with cPanel. I have mysqli, mysqlnd, pdo, pdo_mysql, pdo_sqlite and other modules enabled with PHP current version 7.1.
Here is my database.php code:
<?php $dsn = "MySQL:host=11.62.0.35;dbname=newdatabase"; $username = "memyselfi"; $password = "pa55w0rd"; $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); try { $db = new PDO($dsn, $username, $password, $options); } catch (PDOException $e) { $error_message = $e->getMessage(); include 'DatabaseError.php'; exit; } ?>
Here is my DatabaseError.php code:
... <main> <h1>Database Error</h1> <p>There was an error connecting to the database.</p> <p>Error message: <?php echo $error_message; ?></p> </main> ...
There appears to be a step I am missing.
Solved! Go to Solution.
I knew the IP address of the web-site and MySQL database were two different addresses. I thus made the assumption I could not use host=localhost, but that was the solution. Once I used "localhost", the error message went away in mysqli coding. I reversed the code back for PDO and "localhost" also resolved that code.
Solution:
$host="localhost";
and
$dsn = "MySQL:host=localhost;dbname=newdatabase";
GoDaddy recommended I change the script to use MySQLi, thus I changed the code as follows:
<?php $host = "11.62.0.35"; $dbname = "newdatabase"; $username = "jmemyselfi"; $password = "pa55w0rd"; $dbConn = new mysqli($host, $username, $password, $dbname); if ($dbConn->connect_errno) { echo "Sorry, this website is experiencing problems."; echo "Error: Failed to make a MySQL connection, here is why: \n"; echo "Errno: " . $dbConn->connect_errno . "\n"; echo "Error: " . $dbConn->connect_error . "\n"; exit; } ?>
I received the following error message:
Warning: mysqli::__construct(): (HY000/2003): Can't connect to MySQL server on '11.62.0.35' (110) in /home/ds3tjvumtdmc/public_html/ourlittlechurch/model/database.php on line 7
Sorry, this website is experiencing problems.Error: Failed to make a MySQL connection, here is why: Errno: 2003 Error: Can't connect to MySQL server on '11.62.0.35' (110)
I knew the IP address of the web-site and MySQL database were two different addresses. I thus made the assumption I could not use host=localhost, but that was the solution. Once I used "localhost", the error message went away in mysqli coding. I reversed the code back for PDO and "localhost" also resolved that code.
Solution:
$host="localhost";
and
$dsn = "MySQL:host=localhost;dbname=newdatabase";