Asked  7 Months ago    Answers:  3   Viewed   31 times

I just installed PHP and Apache on my home PC. When I try to call function mysql_connect I get:

fatal error: call to undefined function mysql_connect.

I have loaded php.ini where I have uncommented lines extension=php_mysql.dll and extension=php_mysqli.dll and changed extension directory to extension_dir = "C:phpext" - which is the directory where files php_mysql.dll and php_mysqli.dll are. How can I fix this problem?

Output of phpinfo(): http://jsfiddle.net/MMTwA/

 Answers

86

After looking at your phpinfo() output, it appears the mysql extensions are not being loaded. I suspect you might be editing the wrong php.ini file (there might be multiple copies). Make sure you are editing the php file at C:phpphp.ini (also check to make sure there is no second copy in C:Windows).

Also, you should check your Apache logs for errors (should be in the logs directory in your Apache install.

If you haven't read the below, I would take a look at the comments section, because it seems like a lot of people experience quirks with setting this up. A few commenters offer solutions they used to get it working.

http://php.net/manual/en/install.windows.extensions.php

Another common solution seems to be to copy libmysql.dll and php_mysql.dll from c:PHP to C:WindowsSystem32.

Wednesday, March 31, 2021
 
Raef
answered 7 Months ago
38
  1. Locate the correct php.ini file (check phpinfo() if in doubt)
  2. Locate the line saying

    extension=php_mysql_libmysql.dll
    

    and make sure it is uncommented (no ; in front)

  3. Save
  4. Restart web server
Friday, May 28, 2021
 
alioygur
answered 5 Months ago
14

From the PHP Manual:

Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:

mysqli_connect()

PDO::__construct()

use MySQLi or PDO

<?php
$con = mysqli_connect('localhost', 'username', 'password', 'database');
Wednesday, June 9, 2021
 
sunshinejr
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :