致命错误:调用未定义的函数mysql_connect()

时间:2022-01-03 06:59:32

I have set up PHP, MySQL, and Apache. localhost() for PHP and it is working well. But after I downloaded MySQL, it reports:

我已经建立了PHP,MySQL和Apache。用于PHP的localhost(),它运行良好。但在我下载MySQL之后,它会报告:

Fatal error: Call to undefined function mysql_connect()

致命错误:调用未定义的函数mysql_connect()

How can I fix this?

我怎样才能解决这个问题?

15 个解决方案

#1


29  

Open your terminal and run bellow command.

打开终端并运行bellow命令。

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql 5:

如果你正在运行PHP,你还需要为mysql 5安装php模块:

sudo apt-get install php5-mysql

#2


26  

Use "mysqli_connect"

使用“mysqli_connect”

$con = mysqli_connect("127.0.0.1","root","pass","your_database");

it will gonna work, i fixed my problem with this .

它会工作,我解决了这个问题。

#3


19  

If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.

如果在升级到PHP 7.0后出现此错误,那么您使用的是已弃用的库。

mysql_connect — Open a connection to a MySQL Server
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.

mysql_connect - 打开与MySQL服务器的连接警告此扩展在PHP 5.5.0中已弃用,在PHP 7.0.0中已被删除。相反,应该使用MySQLi或PDO_MySQL扩展。

More here: http://php.net/manual/en/function.mysql-connect.php

更多信息:http://php.net/manual/en/function.mysql-connect.php

#4


6  

Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page for MySQL. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in

验证您的PHP安装是否已使用mysql支持进行编译。创建一个包含<?php phpinfo()的测试网页;出口(); ?>并将其加载到浏览器中。在页面中搜索MySQL。如果你没有看到它,你需要重新编译PHP支持MySQL,或重新安装内置它的PHP包

#5


4  

PHP.INI

Check if you forgot to enable the options below(loads the modules for mysql among others):

检查是否忘记启用以下选项(加载mysql等模块):

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

#6


3  

Use. <?php $con = mysqli_connect('localhost', 'username', 'password', 'database'); ?>

使用。 <?php $ con = mysqli_connect('localhost','username','password','database'); ?>

In PHP 7. You probably have PHP 7 in XAMPP. You now have two option: MySQLi and PDO.

在PHP 7中。您可能在XAMPP中使用PHP 7。您现在有两个选项:MySQLi和PDO。

#7


2  

I had this same problem on RHEL6. It turns out that the mysql.ini file in /etc/php.d only had a module name but needed a full path name. On my RHEL6 system the entry that works is:

我在RHEL6上遇到了同样的问题。事实证明,/ etc / php.d中的mysql.ini文件只有一个模块名,但需要一个完整的路径名。在我的RHEL6系统上,有效的条目是:

; Enable mysql extension module

extension=/usr/lib64/php/modules/mysql.so

After modifying the file, I restarted apache and everything worked.

修改文件后,我重新启动了apache,一切正常。

#8


1  

Am using windows 8 n this issue got resolved by changing the environment variables

我使用的是Windows 8,通过更改环境变量解决了这个问题

follow these steps: Open my computer properties->advanced system settings->Environment variables. Under 'system variables', select 'path' and click on 'edit' In 'variable value', add 'C:\php;' OR the path where php installed.

请按照下列步骤操作:打开我的计算机属性 - >高级系统设置 - >环境变量。在“系统变量”下,选择“路径”并单击“编辑”在“变量值”中,添加“C:\ php;”或者安装php的路径。

click OK and apply the settings and restart the system. It should work.

单击“确定”并应用设置并重新启动系统。它应该工作。

#9


1  

This error is coming only for your PHP version v7.0. you can avoid these using PHP v5.0 else

此错误仅适用于PHP版本v7.0。你可以使用PHP v5.0来避免这些

use it

用它

mysqli_connect("localhost","root","")

i made only mysqli from mysql

我只用mysql制作了mysqli

#10


0  

My solution is here (I needed just to remove the last slash (NB: backward slashes) from PHPIniDir 'c:\PHP\'): Fatal error: Call to undefined function mysql_connect() cannot solve

我的解决方案在这里(我只需要从PHPIniDir'c:\ PHP \'中删除最后一个斜杠(NB:反斜杠):致命错误:调用未定义的函数mysql_connect()无法解决

#11


0  

Check if mysqli module is installed for your PHP version

检查是否为PHP版本安装了mysqli模块

$ ls /etc/php/7.0/mods-available/mysql*
/etc/php/7.0/mods-available/mysqli.ini /etc/php/7.0/mods-available/mysqlnd.ini

Enable the module

启用该模块

$ sudo phpenmod mysqli

#12


0  

This Code Can Help You

本准则可以帮助您

<?php 

$servername = "localhost";
$username = "root";
$password = "";


$con = new mysqli($servername, $username, $password);

?>

But Change The "servername","username" and "password"

但是更改“服务器名称”,“用户名”和“密码”

#13


0  

Here is a quick fix:

这是一个快速修复:

All the pros will probably hate me for this answer. But I got the same error on a server: Fatal error: Uncaught Error: Call to undefined function mysql_connect() that was using PHP 7. Did not have time to rewrite all the mysql code so a quick, temporary fix if anyone needs it is in CPANEL to look for PHP Configuration and change the version for that account to something like PHP 5.4 instead of PHP 7. Then the code worked fine without the above error.

所有职业选手都可能会因为这个答案而讨厌我。但我在服务器上得到了同样的错误:致命错误:未捕获错误:调用使用PHP 7的未定义函数mysql_connect()没有时间重写所有mysql代码,以便快速,临时修复,如果有人需要它是在CPANEL中寻找PHP配置并将该帐户的版本更改为PHP 5.4而不是PHP 7.然后代码工作正常,没有上述错误。

#14


0  

A solution could be to use adapter functions like these to start using mysqli instead of mysql over your entire application:

一个解决方案可能是使用这样的适配器函数来开始在整个应用程序中使用mysqli而不是mysql:

if (!function_exists('mysql_connect')) {
    function mysql_connect($host = '', $user = '', $password = '', $database = '', $port = 0, $socket = '') {
        return mysqli_connect($host, $user, $password, $database, $port, $socket);
    }
}


if (!function_exists('mysql_select_db')) {
    function mysql_select_db($link, $dbname) {
        mysqli_select_db($link, $dbname);
    }
}

#15


-1  

The problem shows up when you're using mysql_connect in your code lines so just add it as in mysqli_cOnnect and it will solve the Problem.
you also Have to then use mysqli throughout your code lines or the Problem would surface again.
example mysql_select_db will then be mysqL_select_db.
That's for selecting Database.

当您在代码行中使用mysql_connect时,问题就出现了,所以只需在mysqli_cOnnect中添加它就可以解决问题。你还必须在整个代码行中使用mysqli,否则问题会再次出现。例子mysql_select_db将是mysqL_select_db。那就是选择数据库。

Thanks hope this helps

谢谢希望这有帮助

#1


29  

Open your terminal and run bellow command.

打开终端并运行bellow命令。

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql 5:

如果你正在运行PHP,你还需要为mysql 5安装php模块:

sudo apt-get install php5-mysql

#2


26  

Use "mysqli_connect"

使用“mysqli_connect”

$con = mysqli_connect("127.0.0.1","root","pass","your_database");

it will gonna work, i fixed my problem with this .

它会工作,我解决了这个问题。

#3


19  

If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.

如果在升级到PHP 7.0后出现此错误,那么您使用的是已弃用的库。

mysql_connect — Open a connection to a MySQL Server
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.

mysql_connect - 打开与MySQL服务器的连接警告此扩展在PHP 5.5.0中已弃用,在PHP 7.0.0中已被删除。相反,应该使用MySQLi或PDO_MySQL扩展。

More here: http://php.net/manual/en/function.mysql-connect.php

更多信息:http://php.net/manual/en/function.mysql-connect.php

#4


6  

Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page for MySQL. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in

验证您的PHP安装是否已使用mysql支持进行编译。创建一个包含<?php phpinfo()的测试网页;出口(); ?>并将其加载到浏览器中。在页面中搜索MySQL。如果你没有看到它,你需要重新编译PHP支持MySQL,或重新安装内置它的PHP包

#5


4  

PHP.INI

Check if you forgot to enable the options below(loads the modules for mysql among others):

检查是否忘记启用以下选项(加载mysql等模块):

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

#6


3  

Use. <?php $con = mysqli_connect('localhost', 'username', 'password', 'database'); ?>

使用。 <?php $ con = mysqli_connect('localhost','username','password','database'); ?>

In PHP 7. You probably have PHP 7 in XAMPP. You now have two option: MySQLi and PDO.

在PHP 7中。您可能在XAMPP中使用PHP 7。您现在有两个选项:MySQLi和PDO。

#7


2  

I had this same problem on RHEL6. It turns out that the mysql.ini file in /etc/php.d only had a module name but needed a full path name. On my RHEL6 system the entry that works is:

我在RHEL6上遇到了同样的问题。事实证明,/ etc / php.d中的mysql.ini文件只有一个模块名,但需要一个完整的路径名。在我的RHEL6系统上,有效的条目是:

; Enable mysql extension module

extension=/usr/lib64/php/modules/mysql.so

After modifying the file, I restarted apache and everything worked.

修改文件后,我重新启动了apache,一切正常。

#8


1  

Am using windows 8 n this issue got resolved by changing the environment variables

我使用的是Windows 8,通过更改环境变量解决了这个问题

follow these steps: Open my computer properties->advanced system settings->Environment variables. Under 'system variables', select 'path' and click on 'edit' In 'variable value', add 'C:\php;' OR the path where php installed.

请按照下列步骤操作:打开我的计算机属性 - >高级系统设置 - >环境变量。在“系统变量”下,选择“路径”并单击“编辑”在“变量值”中,添加“C:\ php;”或者安装php的路径。

click OK and apply the settings and restart the system. It should work.

单击“确定”并应用设置并重新启动系统。它应该工作。

#9


1  

This error is coming only for your PHP version v7.0. you can avoid these using PHP v5.0 else

此错误仅适用于PHP版本v7.0。你可以使用PHP v5.0来避免这些

use it

用它

mysqli_connect("localhost","root","")

i made only mysqli from mysql

我只用mysql制作了mysqli

#10


0  

My solution is here (I needed just to remove the last slash (NB: backward slashes) from PHPIniDir 'c:\PHP\'): Fatal error: Call to undefined function mysql_connect() cannot solve

我的解决方案在这里(我只需要从PHPIniDir'c:\ PHP \'中删除最后一个斜杠(NB:反斜杠):致命错误:调用未定义的函数mysql_connect()无法解决

#11


0  

Check if mysqli module is installed for your PHP version

检查是否为PHP版本安装了mysqli模块

$ ls /etc/php/7.0/mods-available/mysql*
/etc/php/7.0/mods-available/mysqli.ini /etc/php/7.0/mods-available/mysqlnd.ini

Enable the module

启用该模块

$ sudo phpenmod mysqli

#12


0  

This Code Can Help You

本准则可以帮助您

<?php 

$servername = "localhost";
$username = "root";
$password = "";


$con = new mysqli($servername, $username, $password);

?>

But Change The "servername","username" and "password"

但是更改“服务器名称”,“用户名”和“密码”

#13


0  

Here is a quick fix:

这是一个快速修复:

All the pros will probably hate me for this answer. But I got the same error on a server: Fatal error: Uncaught Error: Call to undefined function mysql_connect() that was using PHP 7. Did not have time to rewrite all the mysql code so a quick, temporary fix if anyone needs it is in CPANEL to look for PHP Configuration and change the version for that account to something like PHP 5.4 instead of PHP 7. Then the code worked fine without the above error.

所有职业选手都可能会因为这个答案而讨厌我。但我在服务器上得到了同样的错误:致命错误:未捕获错误:调用使用PHP 7的未定义函数mysql_connect()没有时间重写所有mysql代码,以便快速,临时修复,如果有人需要它是在CPANEL中寻找PHP配置并将该帐户的版本更改为PHP 5.4而不是PHP 7.然后代码工作正常,没有上述错误。

#14


0  

A solution could be to use adapter functions like these to start using mysqli instead of mysql over your entire application:

一个解决方案可能是使用这样的适配器函数来开始在整个应用程序中使用mysqli而不是mysql:

if (!function_exists('mysql_connect')) {
    function mysql_connect($host = '', $user = '', $password = '', $database = '', $port = 0, $socket = '') {
        return mysqli_connect($host, $user, $password, $database, $port, $socket);
    }
}


if (!function_exists('mysql_select_db')) {
    function mysql_select_db($link, $dbname) {
        mysqli_select_db($link, $dbname);
    }
}

#15


-1  

The problem shows up when you're using mysql_connect in your code lines so just add it as in mysqli_cOnnect and it will solve the Problem.
you also Have to then use mysqli throughout your code lines or the Problem would surface again.
example mysql_select_db will then be mysqL_select_db.
That's for selecting Database.

当您在代码行中使用mysql_connect时,问题就出现了,所以只需在mysqli_cOnnect中添加它就可以解决问题。你还必须在整个代码行中使用mysqli,否则问题会再次出现。例子mysql_select_db将是mysqL_select_db。那就是选择数据库。

Thanks hope this helps

谢谢希望这有帮助