MySQL Forums
Forum List  »  PHP

Re: Call to undefined function mysql_connect()
Posted by: Peter Brawley
Date: March 15, 2006 10:37PM

It can be tricky. Here is our c`heat sheet for getting MySQL working with Apache 2 and PHP 4/5 unders Windows. Improvements welcome of course.

Let the PHP installation directory be <PHP_INSTALL_DIR>; c:\php. is best.

1. If you are upgrading from PHP 3 to 4, or from 4 to 5: Stop Apache, rename the old PHP home directory to a descriptive name, e.g. php433, and move the old PHP DLLs out of %windir%\system32 to a backup directory, for example:

md \php433\winfilecopies
cd \php433\dlls
for %f in (*.dll) do move %windir%\system32\%f \php433\winfilecopies

Also move %windir%\php.ini to that winfilecopies backup directory. Make a <PHP_INSTALL_DIR>\includes directory, and copy your PHP include files there.

2. Set PHP path: In the Advanced Properties tab of My Computer, ensure that <PHP_INSTALL_DIR> is in the PATH. If you are installing PHP 4, move all DLLs from both <PHP_INSTALL_DIR>\dlls and <PHP_INSTALL_DIR\sapi to <PHP_INSTALL_DIR>. For PHP 5, that's not necessary—the DLLs are already in <PHP_INSTALL_DIR>.

3. Configure Apache 2 for PHP: Open <APACHE_DIR\conf\Httpd.conf in a text editor and look for the section that contains a list of AddType commands, and add this one:

AddType application/x-httpd-php .php

For PHP 4, in the LoadModule section of Httpd.conf, uncomment or add in:

LoadModule php4_module “c:/php/php4apache2.dll”

For PHP 5 it should be:

LoadModule php5_module "c:/php/php5apache2.dll"

4. Set up php.ini: Make a copy of <PHP_INSTALL_DIR>\php.ini-recommended, name it php.ini, and open it in your text editor. Add or edit the first two settings shown below. If you are installing PHP 5, comment out the third setting, otherwise the fourth:

doc_root = c:\apache\apache2\htdocs ; MUST BE THE SAME AS IN Httpd.conf
session.save_path = c:/temp ; DIRECTORY MUST EXIST
extension_dir = "c:\php\extensions" ; FOR PHP 4 ONLY
extension_dir = "c:\php\ext" ; FOR PHP 5 ONLY

Create c:\temp if it does not exist. The PHP manual says these path arguments need trailing backslashes, but since PHP 4.3 that is not the case.

5. Apache 2, PHP and MySQL: PHP 4.3 for Windows has MySQL extensions linked in, so PHP 4.3 works with MySQL out of the box. PHP 5 needs Connector/PHP files. (Also, some PHP callers may still look for a file named libmysqli.dll even though it does not ship with PHP, so you may want to make a copy of libmysql.dll, name it libmysqli.dll, then copy libmysql*.dll to <APACHEDIR>\apache\bin.) In php.ini, uncomment or add:

extension=php_mysql.dll
extension=php_mysqli.dll

6. CGI mode: If you need to run PHP programs in CGI mode, add to Httpd.conf:

ScriptAlias /php/ "c:/php/"
Action application/x-httpd-php "/php/php.exe"

Save all changes and reboot the machine. To find out whether Apache loads, enter this in a command-line window opened over <APACHEDIR>\apache2\bin:

apache –k start

If there is an error, Apache will report it immediately in this window. To ensure that Apache is serving PHP pages correctly, use your text editor to create a simple PHP page, called phptest.php, containing just this one line:

<?php phpinfo(); ?>

Save to the Apache DocumentRoot folder as phptest.php. To run it, browse http://localhost/phptest.php. If everything is working correctly, you will see a page with the PHP logo and a long list of settings. Whether PHP is running through CGI or inside Apache is indicated by the environment variable orig_script_name. If PHP is running through CGI, this variable is set to /Php/Php.exe. If Apache is running the PHP script directly, this variable will contain the name of your script, /Phptest.php. In either case, if PHP can connect to MySQL then the page shows a MySQL section.

Options: ReplyQuote


Subject
Written By
Posted
Re: Call to undefined function mysql_connect()
March 15, 2006 10:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.