From: http://www.ttlsa.com/php/deprecated-mysql-connect/

php 5个版本,5.2、5.3、5.4、5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in,看意思就很明了,说mysql_connect这个模块将在未来弃用,请你使用mysqli或者PDO来替代。

解决方法1:

禁止php报错

display_errors = On
改为
display_errors = Off

鉴于这个服务器都是给用户用的,有时候他们需要报错(…都是给朋友用的,^_^),不能这做,让他们改程序吧,看方案2.

解决方法2:

常用的php语法连接mysql如下

<?php
$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db('dbname', $link);
 
改成mysqi
<?php
$link = mysqli_connect('localhost', 'user', 'password', 'dbname');

常用mysql建表SQL如下

<?php
//  老的
mysql_query('CREATE TEMPORARY TABLE `table`', $link);
// 新的
mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');

解决方法三:

在php程序代码里面设置报警级别

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

Deprecated的问题就这样解决掉了,不过还是建议大家尽快取消mysql的用法,全部都走向mysqli或者mysqlnd等等。mysql确实是太不安全而且太老旧了。

 
=========================================
完整的测试例子:
<?php

	// 方法一: 老的方法
function test1()
{
$con = mysql_connect("localhost", "root", "123456");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
else
echo "Open mysql db success<br/>";
mysql_close($con);
}
test1(); // 方法二: 新的方法
echo "test2<br>";
function test2()
{
$link = mysqli_connect("localhost", "root", "123456", "");
if(! $link)
{
die('Could not connect: ' . mysql_error());
}
else
echo "Open mysql db success<br/>";
mysqli_close($link);
}
test2(); ?>

运行结果:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/zcm/work/pocketmu/source/vn/vn0/web/mu/th/t1.php on line 6
Open mysql db success
test2
Open mysql db success
 

[mysql] mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in的更多相关文章

  1. 解决 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    转载 php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql ext ...

  2. 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql extens ...

  3. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO

    你有碰上过这样的提示吗? Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in t ...

  4. 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

    因为最近更新的PHP版本,写sql语句,忽然发现不能用了,上网查了一些原因,找到几个方法如下: 1.禁止php报错 display_errors = on 改成 display_errors = of ...

  5. mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    从字面的意思上说:这个函数要被弃用,请使用 mysqlli 或者是 PDO 代替 然后就查手册发现没说,大家一定要查官方最新的手册

  6. 关于Deprecated: mysql_result: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    require_once('connect.php'); $sql = "select * from introduce"; \(query = mysql_query(\)sql ...

  7. The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead [duplicate]

    From: http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-remo ...

  8. 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future:

    php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql extens ...

  9. 错误Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future:

    今天写PHP代码,遇到了这个非常不友好的报错(Deprecated: mysql_connect(): The mysql extension is deprecated and will be re ...

随机推荐

  1. 开源搜素引擎——Nutch

    Nutch简介 Nutch 是一个开源Java实现的搜索引擎.它提供了我们运行自己的搜索引擎所需的全部工具.包括全文搜索和Web爬虫. Nutch 是一个开源Java 实现的搜索引擎.它提供了我们运行 ...

  2. 如何生动形象、切中要点地讲解 OSI 七层模型和两主机传输过程

    作者:繁星亮与鲍包包链接:https://www.zhihu.com/question/24002080/answer/31817536来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...

  3. java中判断字节数组的编码方式是不是UTF-8

    1,用google的工具包,配置maven: <!-- https://mvnrepository.com/artifact/com.googlecode.juniversalchardet/j ...

  4. AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search

    转载请声明 http://blog.csdn.net/u013390476/article/details/50925347 前言: 围棋的英文是 the game of Go,标题翻译为:<用 ...

  5. php设计模式总结-单件模式

    一.单件模式 英文叫做sington.其他语言中有叫做单例模式,其实都是一样的道理.保证只会出现单个实例,所以是单例.翻译成单件,永远只会产生一件,呵呵. 还有翻译成单元素模式.其实关键是看这个英文比 ...

  6. am335x uboot, kernel 编译

    一.设置环境变量 // 写在家目录下面的 .bashrc 里面 export KERNEL_PATH=~/aplex/kernel3.2.0 // kernel 路径 export UBOOT_PAT ...

  7. win10 tensorflow python3*,Multiprocessing using fit_generator(pickle_safe=True) fail问题解决

    由于WIN版本的tensorflow使用 fit_generator时候,出现错误,但是mac 不会出现, 所以的解决方法就是https://github.com/fchollet/keras/iss ...

  8. [开发笔记]-实现winform半透明毛玻璃效果

    亲测win7下可用,win8下由于系统不支持Aero效果,所以效果不是半透明的. 代码: 博客园插入不了代码了..... public partial class Form1 : Form { int ...

  9. Nginx优化(十七)

    [教程主题]:Nginx优化 [课程录制]: 创E [主要内容] Nginx 优化 nginx介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为“engine X”,是 ...

  10. TiDB 源码阅读系列文章(一)序

    原创: 申砾 PingCAP  2018-02-28 在 TiDB DevCon2018 上,我们对外宣布了 TiDB 源码阅读分享活动,承诺对外发布一系列文章以及视频帮助大家理解 TiDB 源码.大 ...