EasyPHP MySQL Connection Problem

I am trying to learn PHP and MySQL and am not getting very far. I have installed EasyPHP-5.3.2i on a Windows 7 64-bit machine. After fixing the install problems with the 64-bit installation I can run EasyPHP fine and manage the db with PHPMyAdmin. The only problem comes in trying to connect using a php program. The connection instruction times out after 30 seconds. I have checked that the browser and EasyPHP can get through the firewall but that does no good. The attached code does not get to the check that the connection was created. I have spent a day and a half on this without significant progress. Suggestions are greatly appreciated.
<?php
$host = 'localhost';
$user = 'website';
$password = 'w9EyhrM4Gu6sUxSP';
$database = 'tlc';
$db_server = mysql_connect($host,$user,$password);
if (!$db_server) die ("Unable to connect to MySQL: ".mysql_error());
?>

Open in new window

LVL 1
rkulpAsked:
Who is Participating?
 
yoyolutConnect With a Mentor Commented:
Hi,

did you try with "127.0.0.1" instead of localhost ? (Or ping localhost is ok ? ) far far away, I had a PC which don't accept localhost...

Phpmyadmin works fine ?

Have a nice day,
Yo
0
 
Dave BaldwinFixer of ProblemsCommented:
That looks exactly like my code which works.  Are you getting an error message?  What is the URL to your program?
0
 
Ray PaseurConnect With a Mentor Commented:
This seems to work for almost every valid installation.  By "valid" I mean that you have actually installed MySQL extensions in PHP.  Try putting your own variable values in there and run it.  Then post back here with any error message.
<?php // RAY_mysql_example.php
error_reporting(E_ALL);


// IMPORTANT PAGES FROM THE MANUALS
// MAN PAGE: http://us2.php.net/manual/en/ref.mysql.php
// MAN PAGE: http://us2.php.net/manual/en/mysql.installation.php
// MAN PAGE: http://us.php.net/manual/en/function.mysql-error.php


// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB CONNECTION: ";
   echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB SELECTION: ";
   echo "<br/> $errmsg <br/>";
   die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES
echo "SUCCESS";

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rkulpAuthor Commented:
Dave and Ray,

Thanks for your responses. I tried Ray's example and got the same output which follows:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\EasyPHP\EasyPHP-5.3.2i\www\RayExample.php on line 19
**********************Beginning of Output*******************
Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\EasyPHP\EasyPHP-5.3.2i\www\RayExample.php on line 19

Fatal error: Maximum execution time of 30 seconds exceeded in C:\EasyPHP\EasyPHP-5.3.2i\www\RayExample.php on line 19
*****************End of Output****************
The ini file contains the extension as well as the default extension directory which contains php_mysql.dll. It may be that the EasyPHP installation did not set the values correctly and I'm too ignorant in this area to detect it. I'll keep playing with that as it is the most promising road to date.
0
 
rkulpAuthor Commented:
yoyolut,

ping localhost and Phpmyadmin both work fine.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
On the main page of phpMyAdmin, it tells you what connection it is using right after the server name.  Mine says (localhost via TCP/IP).  In addition, you have to have a valid MySQL user for that database and the method (localhost).  You can use phpMyAdmin to view and edit the 'Privileges' which is the user names and passwords.  And for the database you are using, you can view and edit the privileges associated with that database to make sure your user is allowed to use that database.
0
 
rkulpAuthor Commented:
Dave,

Thanks for your response. I had done all this. In fact, several times. The user has the privileges and connection method. I have been able to connect from the command line so I know that part is correct.
0
 
Dave BaldwinFixer of ProblemsCommented:
What do you mean "connect from the command line"?
0
 
rkulpAuthor Commented:
I opened a command prompt window and connected to the server using the same username and password.
0
 
Dave BaldwinFixer of ProblemsCommented:
Using the 'mysql' program, PHP script, ???
0
 
rkulpAuthor Commented:
mysql program -- no php. I simply wanted to verify the username and password worked to eliminate that as the problem.
0
 
Dave BaldwinFixer of ProblemsCommented:
Ok, so we know that you have a valid username and password and that PHP does connect to the database server or else phpMyAdmin wouldn't work.  So we're missing something.  Can you look at the phpMyAdmin code to see what methods they're using?  There are at least 3 different ways to connect to the MySQL server with PHP.  Maybe a fourth but in another question, we don't seem to be able to get OBDC to work on a 64-bit system.
0
 
rkulpAuthor Commented:
It works with 'localhost' replaced by '127.0.0.1'
0
 
rkulpAuthor Commented:
I don't know why '127.0.0.1' failed initially but it works now. Thanks for all your help with this frustrating problem.
0
 
Dave BaldwinFixer of ProblemsCommented:
You probably fixed something and didn't know it at the time.  Thanks.
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.