Deprecated: mysql_connect()

2018-12-31 08:01发布

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

The MySQL code is showing me a message in PHP:

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

My connect.inc.php page is

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

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

15条回答
临风纵饮
2楼-- · 2018-12-31 08:35

Warning "deprecated" in general means that you are trying to use function that is outdated. It doeasnt mean thaqt your code wont work, but you should consider refactoring.

In your case functons mysql_ are deprecated. If you want to know more about that here is good explanation already : Why shouldn't I use mysql_* functions in PHP?

查看更多
牵手、夕阳
3楼-- · 2018-12-31 08:36

Deprecated features in PHP 5.5.x

The original MySQL extension is now deprecated, and will generate E_DEPRECATED errors when connecting to a database. Instead, use the **MYSQLi or PDO_MySQL extensions.**

Syntax:

<?php
  $connect = mysqli_connect('localhost', 'user', 'password', 'dbname');

Also, replace all mysql_* functions into mysqli_* functions

instead of

<?php
 $connect = mysql_connect('localhost','root','');
  mysql_select_db('dbname');
?> 
查看更多
泪湿衣
4楼-- · 2018-12-31 08:36

Adding a @ works for me!

I tested with error_reporting(E_ALL ^ E_DEPRECATED);

查看更多
登录 后发表回答