Bị lỗi fatal error call to undefined function mysql_connect

Webmasters and website owners often upgrade PHP to the latest version to avoid security vulnerabilities. This sometimes causes compatibility errors, and one such error is “PHP fatal error call to undefined function mysql_connect()”.

As a part of our Server Management Services, we help our customers to fix such PHP errors.

Here, let’s discuss how to fix the PHP fatal error call to undefined function mysql_connect()

What is a PHP fatal error?

Using older versions of PHP may expose the website to security vulnerabilities and more importantly, bugs that are fixed in the recent versions.

So it is a better idea to upgrade the PHP version to the latest one. However, it is also important to prevent PHP fatal errors on your website.

PHP Fatal Errors also known as Critical Errors can occur after the PHP upgrade​. This error stops/terminates the execution of scripts.

The mysql_connect() PHP fatal error may often occur after upgrading your app to PHP 7+. It will try to use “mysql_connect()” functions of php5 in php7. However, mysql_* functions are completely removed from PHP 7+

Also, Fatal error: Uncaught Error: Call to undefined function mysql_connect() error on WordPress site or dashboard looks like,

Bị lỗi fatal error call to undefined function mysql_connect

How to fix the PHP fatal error call to undefined function mysql_connect() error

After upgrading your PHP version to PHP 7+, there is a chance that you will have the following error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect()

This is due to the removal of the mysql_connect function from PHP 7+ versions.

Let’s see how our Support Engineers fixed the PHP fatal errors

1. Upgrade custom code and WordPress plugins or theme

Initially, we’ll identify whether the site is WordPress or using custom code.

If it is WordPress, the main reason could be compatibility issues. The WordPress theme or plugin may not be compatible with higher PHP versions.

So, we will enable the debug option in wp-config.php and find which WordPress plugin or theme is not compatible with PHP 7+. Then, we will recommend them to upgrade/replace the plugin and theme.

If the site is using custom code, then our developer team will help the customers to make the code compatible with the new PHP version.

This solved the issue.

2. Use MySQLi or PDO

Fatal error: Uncaught Error: Call to undefined function mysql_connect() error can be fixed by the use of MySQLi or PDO.

Many customers are using PHP 7.3 version and WordPress latest version. However, they will get the same error after upgrading.

So, we solved the error by enabling the nd_mysqli extension in the PHP configuration and disabling the mysqli one.

How we fix PHP Fatal error: require_once()

Another issue that we commanly dealing with is PHP Fatal error: require_once(): Failed opening required ‘Mail.php’ (include_path=’.:/usr/share/pear:/usr/share/php’)

Recently, one customer had an issue while sending an email by using PHP mail function with SMTP after upgrading PHP from PHP 5.6 to PHP 7+.

On checking, we have found that the error happened due to an incorrect path to Mail.php. He has created the file mail.php instead of Mail.php and specified as require_once(‘Mail.php’)

So we have renamed the file name to Mail.php and solved the error

[Need assistance to fix PHP Fatal errors? – our Support Engineers will help you.]

Conclusion

In short, php fatal error call to undefined function mysql_connect() error occurs after PHP version upgrade. This is due to the removal of the mysql_connect function from PHP 7+ versions. Today, we saw how our Support Engineers fixed the PHP fatal errors.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

  • Bị lỗi fatal error call to undefined function mysql_connect
  • Diễn đàn
  • Internet & Web & Multimedia
  • Lập trình web
  • Lỗi với hàm mysql_connect()

Bị lỗi fatal error call to undefined function mysql_connect

  1. Lỗi với hàm mysql_connect() Mình mới tìm hiểu PHP và MySQL. Mình viết 1 đoạn code để liên kết PHP với MySQL như sau :

    Code:

    mysql_connect("localhost","root","q") > or die ("Could not connect to MySQL Database"); > ?>

    Khi chạy thử thì báo lỗi như sau : Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\training.php on line 2 Mình viết 1 đoạn code khác để kiểm tra PHP như sau

    Code:

    phpinfo(); > ?>

    thì chạy ra được thông tin của PHP. Như vậy cấu hình PHP đã ổn, không hiểu sao nó không hiểu hàm mysql_connect. Bạn nào biết chỉ giúp mình với.

    [=========> Bổ sung bài viết <=========]

    Đã giải quyết được vấn đề này. Phải cấu hình bằng tay để PHP hiểu các hàm tương tác với mysql.

    1. Search your server for libmysql.dll. Delete any instance of libmysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP.
    1. Search your server for php_mysql.dll. Delete any instance of php_mysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP.
    1. Open your C:\%WIN%\php.ini file in a text editor (Notepad will work).
    1. Search for the line that looks like...

    ;extension=php_mysql.dll

    Change this line to...

    extension=php_mysql.dll

    5. Save the modified php.ini file.

    6. Copy C:\PHP\libmysql.dll and C:\PHP\ext\php_mysql.dll to the C:\%WIN%\system32 folder.

    7. Restart IIS and test it out. Được sửa bởi notbadday lúc 09:25 ngày 05-04-2009Reason: Bổ sung bài viết

    -
    1. > Cám ơn bro rất nhiều, mình thiếu bước 6 nên nó cứ báo Call to undefined function mysql_connect -

    Bookmarks

    Bookmarks

    Quy định

    • Bạn không thể tạo chủ đề mới
    • Bạn không thể trả lời bài viết
    • Bạn không thể gửi file đính kèm
    • Bạn không thể sửa bài viết của mình
    • BB code is On
    • Smilies are On
    • code is On
    • code is On
    • HTML code is Off

    Quy định DDTH.com