自 PHP 5.4 轉換為 PHP 7.0 的腳本

从PHP 5.5开始,mysql_connect等功能已不再可用,因此需要将它们转换为mysqli_connect。

#! /bin/bash
#
#   mysql_to_php7.sh
#
#                       May/30/2017
#
ls $1/*.php > /tmp/tmp01
awk '{print "sed -i -f sed_to_mysqli",$1}' /tmp/tmp01 > /tmp/go_tmp
#
bash /tmp/go_tmp
#
#
#   sed_to_mysqli
#
#               May/31/2017
#
# ---------------------------------------------------
s/mysql_connect(/$link=mysqli_connect(/g
s/mysql_select_db(/mysqli_select_db($link,/g
s/mysql_query(/mysqli_query($link,/g
s/mysql_fetch_array/mysqli_fetch_array/g
s/mysql_fetch_row/mysqli_fetch_row/g
s/mysql_fetch_assoc/mysqli_fetch_assoc/g
s/mysql_close()/mysqli_close($link)/g
s/mysql_error()/mysqli_error($link)/g
s/mysql_num_rows/mysqli_num_rows/g
s/mysql_free_result/mysqli_free_result/g
s/<? /<?php /g
# ---------------------------------------------------

使用方法

./mysql_to_php7.sh フォルダー名

在文件夹中将有 *.php 文件被转换。

广告
将在 10 秒后关闭
bannerAds