Solved

EasyPHP MySQL Connection Problem

Posted on 2010-09-02
15
2,140 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:rkulp
15 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33589609
That looks exactly like my code which works.  Are you getting an error message?  What is the URL to your program?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 50 total points
ID: 33589665
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
 
LVL 1

Author Comment

by:rkulp
ID: 33590945
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
 

Accepted Solution

by:
yoyolut earned 300 total points
ID: 33591039
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
 
LVL 1

Author Comment

by:rkulp
ID: 33591284
yoyolut,

ping localhost and Phpmyadmin both work fine.
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
ID: 33591957
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
 
LVL 1

Author Comment

by:rkulp
ID: 33592052
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33592139
What do you mean "connect from the command line"?
0
 
LVL 1

Author Comment

by:rkulp
ID: 33592635
I opened a command prompt window and connected to the server using the same username and password.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33592713
Using the 'mysql' program, PHP script, ???
0
 
LVL 1

Author Comment

by:rkulp
ID: 33592850
mysql program -- no php. I simply wanted to verify the username and password worked to eliminate that as the problem.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33593171
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
 
LVL 1

Author Comment

by:rkulp
ID: 33596135
It works with 'localhost' replaced by '127.0.0.1'
0
 
LVL 1

Author Closing Comment

by:rkulp
ID: 33596164
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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33598041
You probably fixed something and didn't know it at the time.  Thanks.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now