The Denver Linux, Apache, MySQL and PHP (LAMP) Meetup Group Message Board › Problem connection to mySQL

Problem connection to mySQL

A former member
Post #: 2
I've been fighting with this all night, can't figure out what I'm missing though

here's the stats:
First off it's a WAMP setup (yes I know, but why I'm still on a 2003 Server is a different discussion)

Apache 2.2.4
mySQL 5.0.37
PHP 5.2.4

Also have mySQL Administrator 1.2.12 installed

Apache and PHP work fine, phpinfo() works.

I have a simple test php file:

mysql_connect("localhost", "web", "web123") or die(mysql_error());
echo "Connected to MySQL<br>";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";

mysql_query("CREATE TABLE example(
name VARCHAR(30),
age INT)")
or die(mysql_error());

echo "Table Created!";


if I execute the file from a command line: php testing.php
the table is created and I get the expected output:
Connected to MySQL<br>Connected to DatabaseTable Created!</BODY></HTML>

If I use Firefox to execute the same file (after dropping the table) I receive the Title and a blank browser window and the table is never created.

Does anyone have any idea why?
A former member
Post #: 7
While your code is valid it might not be the easiest to debug ... here is my standard setup that might give you more info ... (though I am doing my best to not say the solution is "install linux" <grin>)

$rc = mysql_connect('localhost','web','web123'­);
if (!$rc) {
echo "could not connect to the server\n".mysql_error();
$rc = mysql_select_db('test');
if (!$rc) {
echo "could not select the db\n".mysql_error();
$rc = mysql_query(...);
if (!$rc) {
echo "ERROR: ".mysql_error();
Sonu K.
user 2496760
Denver, CO
Post #: 9
here's a few things:

Looks like you have your php.ini setting set - not to display errors.

LOG files are a good thing, i suggest you modify your php.ini file (create a page: $> echo '<?php phpinfo(); ?>' > test_phpinfo.php) and find out where you php.ini file is located.

edit your php.ini file and modify the following parameters:


error_log=c:/logs/php.error.log (make sure to make c:/logs dir)


take a look at your error file in mysql - that will tell you if you're having any issues with the initial connect or if the proper permissions haven't been granted to the user - in this case 'web'.


shot in the dark fix:

'localhost' doesn't always work, try the local (machine, eth0) ip address - but before you do make sure that your mysql.user table reflects the correct IP:

mysql> use mysql;
mysql> SELECT host FROM user WHERE User="web";
| host |
| localhost |
1 row in set (0.00 sec)

mysql> UPDATE mysql.user SET host="<your ip>" WHERE User="web"; (note this will update all web users)

then change your 'localhost' to your ip address.
A former member
Post #: 3
Thanks guys, that information brought some things to light that was a problem; but there is still something I must be missing.

Using the code Landon posted I'm getting:
Fatal error: Call to undefined function mysql_connect() in D:\ApacheDocRoot\connect.php on line 5

So It must be something more on the apache side since it works just fine with a command line execution of the script.

If anyone has a spare second or 60, I've made some files available that will hopefully give you all the information and hopefully a trained eye can spot the mistake somehow.


I threw 4 files on there that I'm hoping will help out.
the php.ini and httpd.conf files I'm using and then two php files I think might help.

I've tried every combination I can think of to get this working, but based on that error I know I have missed something.

Just a couple notes that might be relevant:
c:\php\extensions contains both php_mysql.dll and php_mysqli.dll
c:\php\ contains libmysql.dll
A former member
Post #: 2
I think there is an issue with your php.ini.

When you run phpinfo() you should be seeing a section on mysql if it is compiled with support and the correct php.ini is being read.

Here is a copy paste from my output (probably won't keep formatting)

MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.37

Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off

MysqlI Support enabled
Client API library version 5.0.37
Client API header version 5.0.36
MYSQLI_SOCKET /tmp/mysql.sock

Directive Local Value Master Value
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.reconnect Off Off

Windows installations by hand are very tricky. The ini file and where it needs to be stored (like in the System32 folder, etc.) has always been a pain.
I always use a pre-packaged WAMP server if I need a Windows sandbox.
Why? because my Linux distributions always work! :)

If I want a standard packaged install I use :

I like to keep my windows box clear of clutter and wanted the ability to "plug-and-play" a development sandbox.

So the alternative is:

It is a full WAMP server that you can move from machine to machine for development. It fits on an old USB stick and I can take it with me. I have given PHP classes using this setup and handed out a few sticks for "students" to learn how to start dynamic web development.

PS - this windows info is of course just for academic purposes.

If you need some extra assist:
richardjohnjensen at gmail dot com

A former member
Post #: 8
It must be something in where the extension_dir is specified ... I'd go over that and make sure all is happy ... (ignore my previous remarks about mysql conflicting with mysqli, the previous post is obviously proving me wrong)

Another trick I learned many moons ago is when Apache is used as a service it masks any DLL errors you would see normally ... so stop the service and then go into the apache bin directory and start apache manually from the command line ... then if it's having problems finding or loading DLLs they will popup as annoying dialogs for you to learn more ...
A former member
Post #: 4
Well I've narrowed it down a little more. It's something with it running as a service. When it runs a service it must be missing permissions on some files or something, because if I run it from a command prompt with just `httpd` everything works perfect, the mysql module is loaded in php and everything is happy. So now it's just a matter of figuring out the permissions needed without having to run it as administrator.

The next step after that is to get one of my linux boxes set up to replace the windows box as the server. :)
Powered by mvnForum

Our Sponsors

  • Code Talent

    Provides us venue space, food and drinks for our events.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy