Jump to content


This topic is now archived and is closed to further replies.

Guest droz

Call to undefined function mysql_connect()

Recommended Posts

Guest droz
i've been searching the internet for a while.  Tried everything this forum and all other sites say and nothing works.
I just recently installed :

MySql 5.0
Apache 2.2
PHP 5.1.4

on a windows xp computer.

Php and Apache work fine together, and MySql works fine on it's own.
I looked under control panel - administrative tools - services......and MySql is running.

i've done the following changes to my php.ini file :

Change  : ;extension=php_mysql.dll
to : extension=php_mysql.dll
extension_dir = "C:\PHP\ext" (where all my .dll files are located)
and some other things other forums said to try but none worked

I've tried copying the libmysql.dll and libmysqli.dll files into C:\PHP\ext, C:\windows, C:\system, C:\system32, and that didn't work

When i use <?php phpinfo() ?> i read a big section should be on there about mysql, but there isn't.  The only thing refering to mySql is :

Apache Enviornment

variable      Value

Path          C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI 
                Technologies\ATI Control Panel;C:\Program Files\Common Files\Adaptec 
                Shared\System;[b]C:\Program Files\MySQL\MySQL Server 5.0\bin[/b]

Also the same thing, as shown above, is under "PHP Variables" and "Enviornment" sections.

And i made sure it's pointing to the right php.ini file

this is the output of C:\PHP>php -m (which from what i've seen from others, ??? looks normal)
[PHP Modules]

[Zend Modules]

I read in one forum to copy a config.php.dist file over an existing config.php file, but i couldn't find a config.php on my computer.

Also i read that a mysql.so file needs to be loaded into the php.ini file
but when i put extension=mysql.so into my php.ini file the following happens

C:\PHP>php -m
PHP Warning: PHP Startup: Unable to load dynamic library 'c:\PHP\ext\mysql.so'
-The specified module could not be found.
in Unknown on line 0
//followed by what was in the last output

So i searched my computer for a mysql.so file....I didn't find it.

And this is what my .php file looks like that i'm trying to run:




    $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>";



The username and password are correct
I've also tried using another database instead of "test"

Also i have tried using the PEAR DB class to connect to Mysql using the following code:


$username = 'username';
$password = 'password';
$hostspec = 'localhost';
$database = 'bank';

$phptype = 'mysql';

$dsn = "$phptype://$username:$password@$hostspec/$database";

$conn = DB::connect($dsn);
if (DB::isError($conn)) {
die ("Cannot connect:" . $conn->getMessage () . "\n");


And "Cannot connect:DB Error: not found" shows up on the screen when i use that script.

I think thats all i have tried, if anyone can help me it would be appreciated!

Share this post

Link to post
Share on other sites
Please read [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]this thread[/url]. You need to enable the mysql extension and setup the extension_dir directive in the php.ini. Which the post provided explains.

Share this post

Link to post
Share on other sites
Also DONT move the extensions out of the ext directory. Also when you make changes to the php.ini make sure you restart the server. Also I notice you are using Apache2.2, unless I am mistaken, currently PHP doesn't offically support this version of Apache. You might want to downgrade to Apache 2.0.x

Also about the mysql.so file I believe that is for OS other than Windows. PHP Extensions for Windowws are dll files. .so files are for other OS I beleive.

Share this post

Link to post
Share on other sites
I went tired apache 2.0 same thing happened

i double checked to make sure extension_dir = "C:\PHP\ext" was in the right section and it was

any futher help would be appreciated!

Share this post

Link to post
Share on other sites
OKay have you moved a file called libmysql.dll form the root of the PHP folder to the windows folder.

Make sure you move any files and modify any files you restart the server for the new settings to be loaded into memory, otherwise the new settings wont come available until the server is restarted. Also add the PHP folder to the Windows Path variable and add the following line:
PHPIniDir "C:/PHP"

To Apache httpd.conf file too. POlace the php.ini in the PHP folder when you add the PHP folder to Windows PATH variable.

When you create the chnage the PATH variable you must restart your computer.

Share this post

Link to post
Share on other sites
Thanks adding that path variable made it work

Could you tell me why that made it work...if you dont mind ;D

...and sorry i just read that topic in your sig that suggested to do that

Share this post

Link to post
Share on other sites
Basically when you add the PHP folder to the PATH it allows PHP to look for files automatically as it can access itself. It is best to add the PHP folder to the PATH as then all PHP related files are located in one place which is the PHP folder. However instead of creating a PHP folder can threoretically move all the files and folders from the PHP folder to the Windows folder or the System32 Folder.

Share this post

Link to post
Share on other sites


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.