Please list the versions of Apache (apparently 2.2 from your post), mysql (not so important for your PHP problem), and PHP version, and also if you installed PHP as an apache module (per the instructions at the link you provided) or under CGI.
Note: The instructions at the link you provided as specific to PHP version 4 as an apache module on Apache version 2.0. There is not an official Apache 2.2 PHP sapi dll, so if you have Apache 2.2 and followed the instructions exactly, it won't work.
I've since uninstalled Apache 2.2 and installed Apache 2.0 and so PHP (version 4.4.4) is working now. I am now having trouble conencting to mySQL (version 4.1) using PHP. I granted all priviledges to a user called testuser with password testpassword on localhost and created a database called simple with a table called simple_table (as per the guide).
When I run the php code:
// Connect to the database
$dbhost = 'localhost';
$dbusername = 'testuser';
$dbpasswd = 'testpassword';
$database_name = 'simple';
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
or die ('Couldn\'t connect to server.');
$db = mysql_select_db("$database_name", $connection)
or die('Couldn\'t select database.');
// Generate SQL code to store data on database.
$insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';
// Execute SQL code.
mysql_query( $insert_sql )
or die ( 'It Didn\’t Work: ' . mysql_error() );
// Tell User we are done.
echo 'Code Inserted';
I get the message:
Couldn't connect to server.
I there any reason why it can't connect to the database I've created and any way I can check what the problem might be?
1) Add the following line after your opening <?php tag -
I suspect that there will be an error message about an undefined function. If so, the following line in php.ini is commented out and needs to have the ";" removed (stop and start Apache to get the change to take effect) -
2) Try these two lines without the double-quotes surrounding the variable names (the double-quotes should not matter in this case, but you never know) -
$connection = mysql_connect($dbhost,$dbusername,$dbpasswd) or die ('Couldn\'t connect to server.');
$db = mysql_select_db($database_name, $connection) or die('Couldn\'t select database.');
$connection = mysql_connect($dbhost,$dbusername,$dbpasswd) or die ('Couldn\'t connect to server.' . mysql_error());
$db = mysql_select_db($database_name, $connection) or die('Couldn\'t select database.' . mysql_error());
and now get the output:
Couldn't connect to server.Client does not support authentication protocol requested by server; consider upgrading MySQL client
in the web browser window.
in the apache logs I get the error message:
PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\testconn1.php on line 8
I'm currently using mySQL server 4.1. Will uninstalling this and installing mySQL 5.0 solve the problem or is there another way around the problem
It is normally not this difficult getting any version of PHP and mysql to work together.
From the error message it would appear that the client library that PHP is using is not compatible with the mysql version and since the client library that PHP is using is built in, your choices would be to change the version of PHP or the version of mysql. I have used earlier PHP 4 versions with both mysql 4 and 5 and I have used PHP 5 versions with both mysql 4 and 5. I currently don't use PHP 4.
You could check the PHP or mysql forum to see if there is a direct solution.
For testing and development on a PC, I personally use Apache 2.0.59 (latest 2.0 version), PHP 5.1.6 (latest 5.1 version), and mysql 5.0.24a (latest 5.0 version.)
I've downloaded and setup PHP 5 which works. I uncommented the line
in the php.ini file.
I then restarted Apache and run the php file to connect to the mysql database and get the message:
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\testconn.php on line 8
In the PHP folder there's a folder called extensions with the file php_mysql.dll. I've copied this file to ...\Apache Group\Apache2\ along with the other php files. Is this correct or should this be located in a certain folder?
I then deleted all the text in the php.ini file in ...\Apache Group\Apache2\ and saved it. I then restarted Apache and php still works. So I assume the php.ini file that I have been modifying is not the one that is being read by Apache.
The problem is that there isn't a php.ini file in C:\Windows even with all hidden folders/files shown
Is there any way I can tell Apache which php.ini file it should be loading so I can make the appropriate changes to it.
I'm making a mysql backed website where the admin will be able to update news stories and other information on the web site by logging on and simply completing text fields. This will update the database and therefore update the webpage which retrieves the informtion from the database to display it.
I'm creatnig the website on my PC using the APACHE, PHP and mysql installed. Will it be a simple case of altering the database connection details and creating the appropriate datbase and tables on the mysql server when I come to upload it or are there some complexities involved when transfering it from local host to a webserver.
Also, are there any free web hosts that offer php and mysql?