简体   繁体   English

php中的未定义函数mysql_connect()

[英]undefined function mysql_connect() in php

I have mysql-installer-web-community-5.6.25.0, apache_2.4.2-x86-no-ssl and php-5.4.42-Win32-VC9-x86 installed. 我安装了mysql-installer-web-community-5.6.25.0,apache_2.4.2-x86-no-ssl和php-5.4.42-Win32-VC9-x86。

php is working with apache server but not with mysql. php正在使用apache服务器但不使用mysql。 I have enabled extension=php_mysql.dll and extension=php_mysqli.dll in php.ini and restarted my pc.I have tried adding libmysql.dll and php_mysql.dll to system32.But mysql is not displayed in phpinfo(). 我在php.ini启用了extension=php_mysql.dllextension=php_mysqli.dll并重新启动了我的电脑。我尝试将libmysql.dllphp_mysql.dll添加到system32.But mysql不会显示在phpinfo()中。

My phpinfo() is as follows http://192.168.1.104/test.php 我的phpinfo()如下http://192.168.1.104/test.php

Also i tried with the following php code 我也尝试使用以下PHP代码

$continued = mysql_connect("localhost","sonetonix","sonetonix");

if($continued) {
    echo("Connection is succeed");
} else {
    echo("Connection is fail");
}

when i run the code i am getting error as Call to undefined function mysql_connect(). 当我运行代码时,我收到错误,因为调用未定义的函数mysql_connect()。

How can i make php and mysql work. 我怎样才能使php和mysql工作。

Alter the function from mysql_connect() to mysqli_connect() . 将函数从mysql_connect()更改为mysqli_connect() You'll need to subsequently use the MySQLi function library for further SQL queries and processing. 您需要随后使用MySQLi函数库进行进一步的SQL查询和处理。

Using MySQLi instead of MySQL functions is very similar. 使用MySQLi而不是MySQL函数是非常相似的。 The main difference is that you need to return a connection object and then use that in future queries: 主要区别在于您需要返回一个连接对象,然后在将来的查询中使用它:

$db_connection = mysqli_connect("localhost","sonetonix","sonetonix");
if (empty($db_connection)){
    die('Database connection error');
}
$result = mysqli_query($db_connection, "SELECT * FROM users");

If you are running PHP 5.3 or higher this will be enabled by default. 如果您运行的是PHP 5.3或更高版本,则默认情况下将启用此功能。 If you are not running PHP 5.3 or higher you need to updgrade, as older versions of PHP are no longer secure and have outdated functionality. 如果您没有运行PHP 5.3或更高版本,则需要进行升级,因为旧版本的PHP不再安全并且具有过时的功能。 From your question it would appear you are using PHP 5.4 so all this should work. 根据您的问题,您似乎正在使用PHP 5.4,所以这一切都应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM