dtlab08822 2017-07-04 14:40
浏览 93

迁移到PHP7.x,不推荐使用的函数

So here's the problem, the script I purchase is written on PHP 5.x, and I'm using xampp with PHP7.x installed for development. Now I want to migrate my script to PHP7.x. Now I know this was asked a million times already but do you mind if you could take a look at my code and give your thoughts about it, or simply share your knowledge. I would deeply appreciate it.

Here is the code for my config.php

<?php
// mySQL information
$server = 'localhost';                   // MySql server
$username = 'admin';                      // MySql Username
$password = 'admin' ;                         // MySql Password
$database = 'arcade';                  // MySql Database


// The following should not be edited

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

  $con = mysql_connect($server, $username, $password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db($database, $con); 


// Get settings
if (!isset($install)) {
    $sql = mysql_query("SELECT * FROM ava_settings");
    while ($get_setting = mysql_fetch_array($sql)) {
        $setting[$get_setting['name']] = $get_setting['value'];
    }
}
?>

The deprecated functions are:

mysql_connect()
mysql_error()
mysql_fetch_array()
mysql_query()
mysql_select_db()

Now, I don't want to use the PDO approach, I want to use mysqli instead. Am I suppose to just replace the mysql_* into mysqli_*? So it will become like these? I don't want to hide/surpress the deprecate warnings.

mysqli_connect()
mysqli_error()
mysqli_fetch_array()
mysqli_query()
mysqli_select_db()

  • 写回答

2条回答 默认 最新

  • drduh44480 2017-07-04 14:45
    关注

    I just offer you that migrate to PDO driver. Because every update you may see a lot of deprecation errors.

    But if you can not do it the first thing to do would probably be to replace every mysql_* function call with its equivalent mysqli_*, at least if you are willing to use the procedural API -- which would be the easier way, considering you already have some code based on the MySQL API, which is a procedural one.

    Note that, for some functions, you may need to check the parameters carefully: Maybe there are some differences here and there -- but not that many, I'd say: both mysql and mysqli are based on the same library (libmysql ; at least for PHP <= 5.2)

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分