已弃用:mysql_connect() [英] Deprecated: mysql_connect()
问题描述
MySQL代码在PHP中向我显示一条消息:
不推荐使用:mysql_connect():不推荐使用mysql扩展,
将在未来删除:使用mysqli或PDO代替
C:\\ \\ xampp \ htdocs \task\media\\\
ew\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ c $ c> connect.inc.php 页面是<?php
$ connect = mysql_connect('localhost','root','');
mysql_select_db('dbname');
?>
这意味着什么以及如何消除该消息?
<解决方案
MySQLi的方式如下所示:
p> <?php
$ connection = mysqli_connect('localhost','username','password','database' );
运行数据库查询也很简单,几乎与旧方式相同:
<?php
//旧式
mysql_query('CREATE TEMPORARY TABLE`table`',$ connection);
//新建方法
mysqli_query($ connection,'CREATE TEMPORARY TABLE`table`');
关闭包括它们在内的所有不推荐使用的警告_ *:
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
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?
There are few solutions for your problem.
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`');
Turn off all deprecated warnings including them from mysql_*:
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
这篇关于已弃用:mysql_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!