2

I have manually set up a wamp Server on Windows7 with Apache 2.4.23, PHP 5.6.29 and MYSQL Server 5.5. Each time I try to connect to MySQL I get the error:

fatal error: call to undefined function mysql_connect

I have tried the following stackoverflow solution,but I could not find any libmysql.dll in c:\PHP nor copying php_mysql.dll from c:\PHP to C:\Windows\System32 was fruitful: Call to undefined function mysql_connect

Output of my phpinfo(): https://jsfiddle.net/ad0gd90y/

I have also viewed the error log file in Apache:

Installing Apache HTTP Server 2.x with
 DomainName    = example.com
 ServerName    = www.example.com
 ServerAdmin   = admin@example.com
 ServerPort    = 80
 ServerSslPort = 443
 ServerRoot    = c:/Apache24
Rewrote docs/conf/extra/httpd-autoindex.conf.in
 to c:/Apache24/conf/original/extra/httpd-autoindex.conf
Rewrote docs/conf/extra/httpd-default.conf.in
 to c:/Apache24/conf/original/extra/httpd-default.conf
Rewrote docs/conf/extra/httpd-ssl.conf.in
 to c:/Apache24/conf/original/extra/httpd-ssl.conf
Rewrote docs/conf/extra/httpd-multilang-errordoc.conf.in
 to c:/Apache24/conf/original/extra/httpd-multilang-errordoc.conf
Rewrote docs/conf/extra/httpd-info.conf.in
 to c:/Apache24/conf/original/extra/httpd-info.conf
Rewrote docs/conf/extra/httpd-userdir.conf.in
 to c:/Apache24/conf/original/extra/httpd-userdir.conf
Rewrote docs/conf/extra/httpd-mpm.conf.in
 to c:/Apache24/conf/original/extra/httpd-mpm.conf
Rewrote docs/conf/httpd.conf.in
 to c:/Apache24/conf/original/httpd.conf
Rewrote docs/conf/extra/proxy-html.conf.in
 to c:/Apache24/conf/original/extra/proxy-html.conf
Rewrote docs/conf/extra/httpd-vhosts.conf.in
 to c:/Apache24/conf/original/extra/httpd-vhosts.conf
Rewrote docs/conf/extra/httpd-dav.conf.in
 to c:/Apache24/conf/original/extra/httpd-dav.conf
Rewrote docs/conf/extra/httpd-languages.conf.in
 to c:/Apache24/conf/original/extra/httpd-languages.conf
Rewrote docs/conf/extra/httpd-manual.conf.in
 to c:/Apache24/conf/original/extra/httpd-manual.conf
Duplicated c:/Apache24/conf/original/extra/httpd-autoindex.conf
 to c:/Apache24/conf/extra/httpd-autoindex.conf
Duplicated c:/Apache24/conf/original/extra/httpd-default.conf
 to c:/Apache24/conf/extra/httpd-default.conf
Duplicated c:/Apache24/conf/original/extra/httpd-ssl.conf
 to c:/Apache24/conf/extra/httpd-ssl.conf
Duplicated c:/Apache24/conf/original/extra/httpd-multilang-errordoc.conf
 to c:/Apache24/conf/extra/httpd-multilang-errordoc.conf
Duplicated c:/Apache24/conf/original/extra/httpd-info.conf
 to c:/Apache24/conf/extra/httpd-info.conf
Duplicated c:/Apache24/conf/original/extra/httpd-userdir.conf
 to c:/Apache24/conf/extra/httpd-userdir.conf
Duplicated c:/Apache24/conf/original/extra/httpd-mpm.conf
 to c:/Apache24/conf/extra/httpd-mpm.conf
Duplicated c:/Apache24/conf/original/httpd.conf
 to c:/Apache24/conf/httpd.conf
Duplicated c:/Apache24/conf/original/magic
 to c:/Apache24/conf/magic
Duplicated c:/Apache24/conf/original/charset.conv
 to c:/Apache24/conf/charset.conv
Duplicated c:/Apache24/conf/original/extra/proxy-html.conf
 to c:/Apache24/conf/extra/proxy-html.conf
Duplicated c:/Apache24/conf/original/extra/httpd-vhosts.conf
 to c:/Apache24/conf/extra/httpd-vhosts.conf
Duplicated c:/Apache24/conf/original/extra/httpd-dav.conf
 to c:/Apache24/conf/extra/httpd-dav.conf
Duplicated c:/Apache24/conf/original/mime.types
 to c:/Apache24/conf/mime.types
Duplicated c:/Apache24/conf/original/extra/httpd-languages.conf
 to c:/Apache24/conf/extra/httpd-languages.conf
Duplicated c:/Apache24/conf/original/extra/httpd-manual.conf
 to c:/Apache24/conf/extra/httpd-manual.conf

I am totally helpless as how to solve this problem. Also what is libmysql.dll used for? Is there any installation order to get it all right(I installed apache followed by php and mysql at last)? Thanks in advance!

Community
  • 1
  • 1
Parveez Ahmed
  • 1,279
  • 4
  • 15
  • 28
  • Possible duplicate of [Fatal error: Call to undefined function mysql\_connect()](http://stackoverflow.com/questions/10615436/fatal-error-call-to-undefined-function-mysql-connect) – Dez Dec 31 '16 at 13:51
  • Have you tried using `mysqli_` to connect/query with? You didn't post any php/mysql code so it's harder to say. – Funk Forty Niner Dec 31 '16 at 14:18
  • I will try soon mysqli_ version of my code. All that I tried a simple connecting script using mysql_connect("$host", "$username", "$password") followed by mysql_select_db("$db_name") which woks fine in my older XP machine where I deployed wamp server with PHP 5.2.5 – Parveez Ahmed Dec 31 '16 at 14:29
  • I have also a confusion over the meaning of "deprecate" when it is said "mysql_* is deprecated in PHP 5.5 and removed in PHP 7.0.", because the literal meaning of deprecate is "to recommend against a function that still works but has been replaced". In this case, it should still work in PHP 5.6.29 as it has not been yet removed from this version. Is it right sir? @Fred-ii- – Parveez Ahmed Dec 31 '16 at 14:39
  • @rosemary only if the mysql_ libraries are installed. – Funk Forty Niner Dec 31 '16 at 14:41
  • 1
    this could also be a permissions issue. Did you try running as admin? if you haven't already. Win7 can be touchy that way. You said that you did a manual install; you should try uninstalling and choosing the auto install and choose the right one if 32 was used, use 64 bit if you have a 64 bit system. – Funk Forty Niner Dec 31 '16 at 14:42
  • I didn't try running as admin if you mean logging windows as admin? @Fred-ii- – Parveez Ahmed Dec 31 '16 at 14:52
  • Is there any way to check whether mysql_ libraries are installed? If not, can it be downloaded? @Fred-ii- – Parveez Ahmed Dec 31 '16 at 14:54
  • 1
    Deprecated means that it is no longer supported or recommended and will give warnings (but should still run). You're right that it should still work in PHP 5.6.29. – LStarky Dec 31 '16 at 14:57
  • What do you mean that you have MANUALLY set up the WAMP server? Did you install from here? http://www.wampserver.com/en/ If not, this is how you should install WAMP. – LStarky Dec 31 '16 at 14:58
  • see these Q&A's http://stackoverflow.com/q/2198154/ --- http://stackoverflow.com/q/6285141/ so see which libraries are loaded. From seeing your config, the PDO itself didn't appear to have been installed. This is another http://stackoverflow.com/q/11097531/ and see the duplicate link that was closed with. There isn't anything I can think of at this point. – Funk Forty Niner Dec 31 '16 at 14:59
  • "I have manually set up a wamp" meaning I downloaded the binaries and extracted in the respective folders (PHP,Apache24) configuring httpd.conf and php.ini and finally installed MySQL Server 5.5. I have not used a ready made package like wamp. Also edited php.ini to enable extension for mysql etc @Fred-ii- – Parveez Ahmed Dec 31 '16 at 15:06
  • Sorry Rosemary, I honestly don't know what else to say/do to help you. Someone gave you an answer below; you should ask them to see if they can help you further. I really wish you well with this. – Funk Forty Niner Dec 31 '16 at 15:26

1 Answers1

1

Most likely you're copying code from an older site to a newer version of PHP. The code mysql_connect is deprecated in PHP 5.5 and removed in PHP 7.0. You also need to make sure that PHP was compiled with MySQL support.

Solution 1: Check for MySQL Support

Detecting mysql support in php

Use the above link to determine whether PHP was compiled using MySQL support. If it was not, then go ahead and re-install PHP or WAMP with the proper support (PDO and MySQL).

Solution 2: Downgrade PHP

If the problem is related to mysql_connect and related mysql_ functions being deprecated, you could change the PHP version in your WAMP installation to something earlier than 7.0 by adjusting the version it's using in the settings in the toolbar. Note that for versions between 5.5 and 7.0, you'll still probably get deprecated function warnings in your error log and possibly on your code output, depending on what errors you're displaying (which can be adjusted in php.ini).

enter image description here

Solution 3: Fix Your Code

Regardless of the above, the best solution is to upgrade your PHP code so that it does not use the deprecated mysql_connect, mysql_query and other related legacy mysql functions. Depending on the size of your code, this could be a short or lengthy process. However, it's important to consider doing this because the older mysql functions have several security vulnerabilities, such as SQL injection, and your website may be vulnerable to hacking attacks if you don't take the time to upgrade your code.

Community
  • 1
  • 1
LStarky
  • 2,685
  • 1
  • 16
  • 47
  • *"to something earlier than 7.0"* - The OP's PHP version is 5.6.29 – Funk Forty Niner Dec 31 '16 at 14:17
  • Okay, then you're probably still getting a warning about mysql_connect being deprecated. Try a version before 5.5 (if you're going with Solution 1 and security is not a great threat). – LStarky Dec 31 '16 at 14:53
  • In the phpinfo() page it shows nothing about MySQL nor even MySQLi. All that it shows is "mysqlnd". It means won't mysqli work either,that is to say, this PHP version does not support for it? @LStarky – Parveez Ahmed Dec 31 '16 at 15:35
  • Correct. So, you'll need to reinstall WAMP and be sure to include PDO and MySQL support. – LStarky Dec 31 '16 at 15:48
  • How do I make sure ? @LStarky – Parveez Ahmed Dec 31 '16 at 15:59
  • You already did. If `php_info()` doesn't show anything about MySQL, the library is not installed. Don't try to install the file manually. Reinstall WAMP with the proper settings. – LStarky Dec 31 '16 at 16:51