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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

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
der_23Author Commented:
I've finally switched to running apache server.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Vitaliano GiannangeliDirectorCommented:
The accepted solution IS NOT a solution. For those that can't change to apache this thread is not usefull.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.