Jump to content

Recommended Posts

PHP works because I can see phpinfo(); but when I try something like

 

// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';

// username and password to log onto db server
$dbUser='root';
$dbPass='XXXX;

// name of database
$dbName='test';

    $link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
    print "Connected successfully<br>";
    mysql_select_db("$dbName") or die("Could not select database");
    print "Database selected successfully<br>";

// close connection
mysql_close($link);

 

I am served 'Fatal error: Call to undefined function mysql_connect() in C:\WEB\test.php on line 12'

 

From php.ini:

; Directory in which the loadable extensions (modules) reside.

 

extension_dir ="C:\Program Files\PHP\ext"

 

;;;;;;;;;;;;;;;;;;;;;;

; Dynamic Extensions ;

;;;;;;;;;;;;;;;;;;;;;;

;

; If you wish to have an extension loaded automatically, use the following

; syntax:

;

;  extension=modulename.extension

;

; For example, on Windows:

;

;  extension=php_mysql.dll

;

; ... or under UNIX:

;

;  extension=msql.so

;

; Note that it should be the name of the module only; no directory information

; needs to go here.  Specify the location of the extension with the

; extension_dir directive above.

 

extension=php_mysql.dll

 

My path is

 

PATH=C:\Program Files\PHP\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wb

em;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Common

Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLSha

red\;C:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;C:\Program Files\

QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.0\bin

 

 

Any ideas???

Run phpinfo and tell what the Configuration File (php.ini) Path and Loaded Configuration File lines return

 

Also can you tell me where your php.ini is located.

 

As a note I find it best to use forward-slashes for paths (/) rather than backslashes.

There's your problem PHP is not reading the php.ini in C:\Program Files\PHP

 

In Apache's httpd.conf file have you set the PHPIniDir directive? If you havn't add the following to the httpd.conf:

PHPIniDir "C:/Program Files/PHP"

 

Save the httpd.conf and restart Apache. Rerun phpinfo() and check that the Loaded Configuration File line is set to C:\Program Files\PHP

Thank you, I made the change but still can't connect to MySQL??

 

I am trying:

<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';

// username and password to log onto db server
$dbUser='root';
$dbPass='mazlema';

$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
print "Connected successfully<br />";

// close connection
mysql_close($link);
?>

 

and I get a blank page... no code at all if I do a view source

Now that php is reading the php.ini, it is likely that the display_errors setting is off.

 

When learning php, developing php code, or debugging php code, always turn on full php error reporting to get php to help you. Use the following two values in php.ini -

 

error_reporting  =  E_ALL | E_STRICT
display_errors = On

 

You can leave off the | E_STRICT on the first one if you are dealing with older code and don't care if it is using depreciated functions.

 

Stop and start your web server to get any changes made to php.ini to take effect.

// hostname or ip of server (for local testing, localhost should work)

$dbServer='localhost';

 

// username and password to log onto db server

$dbUser='root';

$dbPass='mazlema';

 

$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");  ---- Line 9 ---

print "Connected successfully<br />";

 

// close connection

mysql_close($link);

under which section?

 

mysql is in the paths...

Earlier I instructed you to added the PHPIniDir directive to the httpd.conf did you follow this step after:

Save the httpd.conf and restart Apache. Rerun phpinfo() and check that the Loaded Configuration File line is set to C:\Program Files\PHP\php.ini

 

Is the Loaded Configuration File line set correct? This line needs to be set to the php.ini path PHP is reading. Also in order to identify whether the mysql extension has loaded successfully is by looking for a separate MySQL heading when running phpinfo().

'Earlier I instructed you to added the PHPIniDir directive to the httpd.conf did you follow this step after:

Save the httpd.conf and restart Apache. Rerun phpinfo() and check that the Loaded Configuration File line is set to C:\Program Files\PHP\php.ini'

 

I did do this and php info returns

 

Loaded Configuration File C:\Program Files\PHP\php.ini

 

I do not have a separate MySQL heading when running phpinfo... I have

 

Configuration

PHP Core

apache2handler

Apache Environment

HTTP Headers Information

bcmath

calendar

com_dotnet

ctype

date

dom

filter

ftp

hash

iconv

json

libxml

odbc

pcre

Reflection

session

SimpleXML

SPL

standard

tokenizer

wddx

xml

xmlreader

xmlwriter

zlib

 

Additional Modules

Environment

PHP Variables

 

PHP License

And you have uncommented the mysql extension in the php.ini and setup the extension_dir path correctly?

 

Looks like php is is still having issues loading the mysql extension. Scan your computer for any files called php_mysql.dll and libmysql.dll

 

Windows should only find one instance of php_mysql.dll which should be in your php ext folder (C:\Program files\php\ext) however for libmysql.dll only two instances should be found, one in the root of the php folder and the other in the bin folder for mysql.

 

If Windows finds any extract files, either delete them or temporarily rename them.

 

Also ensure you are restarting Apache when you make any changes to the php.ini and/or have removed any files called php_mysql.dll and libmysql.dll

 

You might also want to enable a setting called display_start_errors too within the php.ini

I had to create a C:\Program files\php\ext folder myself as it was not present after the install... in it I copied libmySQL.dll

 

The below is from my php.ini

 

;;;;;;;;;;;;;;;;;;;;;;

; Dynamic Extensions ;

;;;;;;;;;;;;;;;;;;;;;;

;

; If you wish to have an extension loaded automatically, use the following

; syntax:

;

;  extension=modulename.extension

;

; For example, on Windows:

;

;  extension=php_mysql.dll

;

; ... or under UNIX:

;

;  extension=msql.so

;

; Note that it should be the name of the module only; no directory information

; needs to go here.  Specify the location of the extension with the

; extension_dir directive above.

 

extension=php_mysql.dll

 

;;;;;;;;;;;;;;;;;;;;;;;;;

; Paths and Directories ;

;;;;;;;;;;;;;;;;;;;;;;;;;

 

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

;

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

 

; The root of the PHP pages, used only if nonempty.

; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root

; if you are running php as a CGI under any web server (other than IIS)

; see documentation for security issues.  The alternate is to use the

; cgi.force_redirect configuration below

doc_root =

 

; The directory under which PHP opens the script using /~username used only

; if nonempty.

user_dir =

 

; Directory in which the loadable extensions (modules) reside.

extension_dir ="C:\Program Files\PHP\ext"

 

 

php_mysql.dll does not exist on my computer

I have downloaded php_mysql.dll from http://dev.mysql.com/get/Downloads/Connector-PHP-mysqlnd/php_5.2.1-mysqlnd-5.0.1-beta.zip/from/pick and extracted to my c:\program files\php\ext folder.

 

I stopped and re-started Apache without any change

 

I still do not have a MySQL are displayed to me when I view phpinfo();

I guess you installed PHP using the installer. Go to php.net and download the zip binaries package instead.

 

Once downloaded extract the files in the zip to C:\Program Files\PHP overwriting existing files and folders. The php installer comes with limited files where as the zipped binaries comes with all files.

 

Also did you enable the display_startup_errors setting within the php.ini too? With this setting enabled PHP will report back any errors when Apache is being (re)started.

 

Make sure Apache is restarted afterwards in order for the new files to be loaded.

Originally I downloaded and installed PHP 5.2.5 installer [19,803Kb] - 15 November 2007 from http://www.php.net/downloads.php

 

I renamed my self made ext folder to old-ext

 

I just downloaded PHP 5.2.5 zip package [9,713Kb] - 08 November 2007 from the same place, I extracted the ext and extras folder (another that I did not have) to c:\program files\php. I then copied libmySQL.dll from old-ext to ext.

 

Stopped and restarted Apache and now my test script

<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';

// username and password to log onto db server
$dbUser='root';
$dbPass='mazlema';

$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
print "Connected successfully<br />";

// close connection
mysql_close($link);
?>

 

displays Connected successfully

 

Thank you very much everyone for your time and help... is there anything else I should check to be sure that my php install is complete?

Yup everything seems to be working. However do restart your computer too just be sure everything is working as it should be.

 

As a general rule of thumb I always avoid the PHP installer (especially if PHP is being installed with Apache). I find it can cause more problems, a good old fashioned manual install is always best.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.