弃用:mysql_connect() [英] Deprecated: mysql_connect()

查看:28
本文介绍了弃用:mysql_connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此警告,但程序仍能正常运行.

I am getting this warning, but the program still runs correctly.

MySQL 代码向我显示了一条 PHP 消息:

The MySQL code is showing me a message in PHP:

已弃用:mysql_connect():mysql 扩展已弃用,并且将来会被移除:使用 mysqli 或 PDO 代替C:\xampp\htdocs\task\media\new\connect.inc.php 第 2 行

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\task\media\new\connect.inc.php on line 2

我的connect.inc.php页面是

<?php
  $connect = mysql_connect('localhost','root','');
  mysql_select_db('dbname');
?>

这是什么意思,我该如何消除该消息?

What does this mean and how can I eliminate the message?

推荐答案

有几个解决方案可以解决您的问题.

There are a few solutions to your problem.

MySQLi 的方式是这样的:

The way with MySQLi would be like this:

<?php
$connection = mysqli_connect('localhost', 'username', 'password', 'database');

运行数据库查询也很简单,几乎与旧方式相同:

To run database queries is also simple and nearly identical with the old way:

<?php
// Old way
mysql_query('CREATE TEMPORARY TABLE `table`', $connection);
// New way
mysqli_query($connection, 'CREATE TEMPORARY TABLE `table`');

关闭所有已弃用的警告,包括来自 mysql_* 的警告:

Turn off all deprecated warnings including them from mysql_*:

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

需要替换的确切文件和行位置是/System/Startup.php > line: 2" error_reporting(E_All);替换为 error_reporting(E_ALL ^ E_DEPRECATED);

The Exact file and line location which needs to be replaced is "/System/Startup.php > line: 2 " error_reporting(E_All); replace with error_reporting(E_ALL ^ E_DEPRECATED);

这篇关于弃用:mysql_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆