logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Apache = PHP + MySQL Trouble!
Author
shlumph123



Joined: 07 May 2007
Posts: 4

PostPosted: Mon 07 May '07 2:45    Post subject: Apache = PHP + MySQL Trouble! Reply with quote

Hi,

I am currently running:
-Microsoft Windows XP Pro
-Apache 2.2.4
-PHP5.2.1
-MySQL5.0.37

I have everything installed and working independently. I also have PHP working with apache perfectly. My trouble is, PHP isn't working with MySQL. I want to build data driven web sites; learn PHP and MySQL technologies, but first I need to resolve this pain in my ass!

I've tried numerous tutorials, and just can't seem to get it to work.

This is my error:
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\testDB.php on line 9

Here is the part of the testDB.php code:
# Define MySQL Settings
define("MYSQL_HOST", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASS", "password");
define("MYSQL_DB", "test");

$conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error()); <---- Line 9 , password is replaced with MySQL password

Here is what I did:
-Installed Apache 2.2.4 into C:\Program Files\Apache Software Foundation\Apache2.2

-Placed extracted php5.2.1-win32 files into C:\php

-Installed MySQL into C:\Program Files\MySQL ... and checked the box that add's it to my windows path

-Renamed php.ini-recommeded to php.ini, and added C:\php to my windows path.

-Added these four lines to my apache httpd.conf file:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "c:/windows"

Changs to my php.ini file (uncommented):
extension_dir = "C:\php\ext"
session.save_path = "C:\WINDOWS\temp"
extension=php_mysql.dll
extension=php_mysqli.dll in php.ini

I also copied the libmysql.dll from mysql\bin to apache\bin

Any help is greatly appreciated,
Thanks,
Rob
Back to top
PaRK_7677



Joined: 01 Jun 2006
Posts: 65
Location: Missouri

PostPosted: Mon 07 May '07 3:02    Post subject: Reply with quote

Try copying libmysql.dll into \Windows\System32

If you prefer it not be in a system directory you'll have to add the path it currently resides in into PATH (here's how) (add your full path to \apache\bin to PATH). Requires reboots most of the time.
Back to top
shlumph123



Joined: 07 May 2007
Posts: 4

PostPosted: Mon 07 May '07 3:12    Post subject: Reply with quote

I tried this, it's still not working.

I will not sleep until it's works! Neutral
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 07 May '07 3:31    Post subject: Reply with quote

re: your httpd.conf directive:
Code:
# configure the path to php.ini
PHPIniDir "c:/windows"

Are you sure your php.ini file (the one you edited to enable MySQL) is in C:\WINDOWS, not in C:\PHP ?

Just a thought...

-tom-
Back to top
shlumph123



Joined: 07 May 2007
Posts: 4

PostPosted: Mon 07 May '07 4:31    Post subject: Reply with quote

Ok, I fixed that, and it seems to be working a little better. I think PHP is communicating with MySQL now. However, there is another problem.

Now I get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 15

Here is my line 15: while ($field = mysql_fetch_array($res))

Does anyone have an idea how to fix this error?

I've been following this tutorial, to get an idea where I am at
http://www.bicubica.com/apache-php-mysql/index.php#configuring-php-mysql

Could it be that I'm using MySQL 5.0.37 instead of 5.0.27?
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 07 May '07 4:54    Post subject: Reply with quote

I took a quick look, and I think this tutorial has a typo in test.php on line 12.

The SELECT statement in PHP should be like the SELECT statement that you previously used at the mysql> prompt:
Code:
$sql = "SELECT * FROM name";


"test" is the database name.
"name" is the table that you want to SELECT from.

-tom-

p.s. Don't forget to remove the libmysql.dll from your Windows\System32\ directory if it doesn't need to be there.
This can trip you up later (...even years later...) if you forget that there's a version 5.0.37 library here which gets loaded instead of the one you intend to use.
Back to top
shlumph123



Joined: 07 May 2007
Posts: 4

PostPosted: Mon 07 May '07 5:31    Post subject: Reply with quote

It is working now. Thank you for your help, Tom! I've been pulling my hair out. This solves the problem.

Best regards,
Rob
Back to top


Reply to topic   Topic: Apache = PHP + MySQL Trouble! View previous topic :: View next topic
Post new topic   Forum Index -> Other Software