Cannot connect with mysql on IIS web server on windows server 2012

Hi,

I'm using windows server 2012 R2. I've a problem with trying to connect php to mysql on the IIS server. This is my PHP code

<?php
ini_set('display_errors',1);
error_reporting(-1);
$con = mysqli_connect("127.0.0.1", "root", "XXXXXX", "neda_multi") or die (mysqli_connect_error());

if(!$con)
echo "no";
else
echo "yes";
?>

When running the page on the browser, this is the error I get.

Warning: mysqli_connect(): (00000/0): in C:\inetpub\wwwroot\test-connect.php on line 4

I'm able to connect to mysql from the cmd line. What could be the problem? where should I look?

Earlier, I didn't have any problem connecting to the database, then all of a sudden this problem started to occur. Please help.
der_23Asked:
Who is Participating?
 
der_23Author Commented:
I've finally switched to running apache server.
0
 
Dave BaldwinFixer of ProblemsCommented:
How are you connecting from the command line?  Is "127.0.0.1" defined on your system?  What happens if you run that PHP code above on the command line?
0
 
der_23Author Commented:
Here's more detail.

Untitled.pngUntitled-1.pngUntitled-3.gifUntitled-2.png
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
Dave BaldwinFixer of ProblemsCommented:
The 'mysql' command line program does not use TCP/IP for a local connection unless you specify an IP address.  Try this on the command line for a test.
mysql --host=127.0.0.1 -uroot -pXXXXX

Open in new window

I'm assuming that your PHP code is running on the same machine as the MySQL server?
0
 
der_23Author Commented:
Yes, my php code is running on the same machine as the MySQL server

error1.gif
0
 
enrmmobaCommented:
Have you tested the connection with mysql_query instead of mysqli? just to check and see if the problem is with your mysqli extensions in php.ini
0
 
der_23Author Commented:
Same error
error2.gif
0
 
enrmmobaCommented:
Check the PHP error log for a more detailed error explanation:

Make sure logging is on in php.ini

log_errors = On

Open in new window


then enable error_log to write to syslog (whichis the Event Viewer on Windows machines)

error_log = syslog

Open in new window


you should be able to view the full error in event viewer now, note that after editing the php.ini you need to restart the web server so that the changes you made take effect.
0
 
Dave BaldwinFixer of ProblemsCommented:
That's a puzzle.  Of course it all works on my old machines.  Do you have any other program that is successfully connecting to your MySQL server?
0
 
Dave BaldwinFixer of ProblemsCommented:
Did that make any difference?
0
 
der_23Author Commented:
yes, it works now
0
 
Dave BaldwinFixer of ProblemsCommented:
Good, glad you got it fixed.
0
 
der_23Author Commented:
I wasn't able to solve the issue so switched to Apache server instead.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.