tags:

views:

112

answers:

5

I have MySQL running such that I can open a client command line and log on and make databases, tables, etc.

I wanted to do some AJAX. Doing AJAX with ASP, SQL Server, etc is not advisable since both places where I am hosting my websites do not use the Microsoft products. So I am forced to do my development with PHP and MySQL.

I just about have everything set up. I have set up IIS so that I can go to my localhost and I can test out web pages. I have PHP installed so that I can pull up the PHP setting pages.

The problem occurs when I try to bring up the MySQL database in PHP. I use this very simple PHP command:

<?php

$con = mysql_connect('localhost', 'testuser', 'testpassword');

?>

When I try to connect to the mysql database through PHP, I get this error:

Click here

I figure the problem must be in the settings that are in the php.ini. But it seems that my php.ini is set up for MySQL although it is not mentioned in the output when I query the phpinfo page with this code

Here is the result from this:

Click here

A: 

Which version of PHP are you running and are you sure you have MySQL installed and running on localhost with a username of "testuser" and a password of "testpassword" (and have you reloaded the privilege tables after creating those users)?

Have you got IIS configured to log errors into a file - does that provide any more information?

Richy C.
A: 

Create a new PHP file that contains the following:

<?php
phpinfo();
?>

This will helpy you to discover if MySQL has been compiled in properly etc. Can you access the MySQL server from the command line; using something similar to:

mysql -u testuser -ptestpassword testdatabase

If you get a prompt from MySQL, the service is running and we can better help from there.

Hope that helps a little!

Gav
A: 

Are you selecting the database? After your connect statement, you need to use:

mysql_select_db($databaseName, $conn);

Documentation here: http://php.net/mysql_select_db

Will Morgan
+2  A: 

It looks that your php is missing mysql module

in php.ini make sure that you have correct extensions path eg.:

extension_dir = "C:\php\ext"

and make sure you have commented out:

extension=php_mysql.dll
extension=php_mysqli.dll
Engrost
A: 

Hi!

What I would do is to download the complete package in one go (Server, MySQL and PHP). There are tons of good resources like WAMP or MAMP (for MAC users). Once you download the package the installation is just easy and you don't have to set anything as it does it automatically.

They also have phpMyAdmin where you can manage your database and its users and privileges.

Once you got your server running you can test that code that seems fine for me. Try running something like this:

<?php
      $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
      if (!$link) {
              die('Could not connect: ' . mysql_error());
      }
      echo 'Connected';
      mysql_close($link);
?>

Cheers

Teknotica
So, MySQL is no longer enabled by default, so the php_mysql.dll DLL must be enabled inside of php.ini. How is this done? I searched php.ini and I did not find php_mysql.dll.
xarzu