MySQL Forums
Forum List  »  PHP

PDO connection not working
Posted by: Stephen Roberts
Date: September 05, 2016 08:20AM

I am using IIS 8, PHP 7.0.10 and MySQL 5.7 on MS Server 2012 R2 on my network at home. I am following examples in a book PHP & MySQL: Novice to Ninja by Kevin Yank. I have an index.php file with the following code:

try
{
$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'xxxx', 'xxxxxxxx');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$error = 'Unable to connect to the database server.';
include 'error.html.php';
exit();
}

On another computer on my network I get the error from the above code that I was unable to connect to the database. After much searching on the internet I am no closer to finding the solution to my problem. I tried replacing localhost with the IP address 170.0.0.1; with the name of the server; with the website name (www.website.com) but nothing seems to work. I double checked the username and password and that is not the problem. The database is up and running. What process should I follow to debug this issue?

Options: ReplyQuote


Subject
Written By
Posted
PDO connection not working
September 05, 2016 08:20AM
September 05, 2016 09:45AM
September 05, 2016 01:09PM
September 05, 2016 04:03PM
September 06, 2016 06:57AM
September 06, 2016 08:04AM
September 06, 2016 09:21AM
September 06, 2016 09:45AM
September 05, 2016 03:57PM
September 06, 2016 07:31AM
September 06, 2016 07:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.