mysql_connect
让PHP7兼容老版本的php5.5.x或者5.6下的mysql_connect的处理代码
星期一, 九月 9th, 2019 | linux, php | 没有评论
1.昨天折腾了下服务器,把系统从centos6.5更新到7.6,也把对应的php版本升级到了php7.0.x系列
2.好多年没有再怎么写php代码了,以前写的也是在php5.5.x的版本写的,升级后发现程序无法使用,郁闷ing
3.跟踪下 /var/opt/remi/php70/log/php-fpm 下的 www-error.log发现是 php7已经不支持mysql_connect
4.网上找了下兼容的代码新增了 mysql_num_rows的函数的处理,我以前的老代码又可以欢快的跑起来了,记录下,也方便需要的朋友
$dbhost = DATA_HOST; $dbport = 3306; $dbuser = DATA_USERNAME; $dbpass = DATA_PASSWORD; $dbname = DATA_NAME; if(!function_exists('mysql_connect')){ function mysql_connect($dbhost, $dbuser, $dbpass){ global $dbport; global $dbname; global $mysqli; $mysqli = mysqli_connect("$dbhost:$dbport", $dbuser, $dbpass, $dbname); return $mysqli; } function mysql_select_db($dbname){ global $mysqli; return mysqli_select_db($mysqli,$dbname); } function mysql_fetch_array($result){ return mysqli_fetch_array($result); } function mysql_fetch_assoc($result){ return mysqli_fetch_assoc($result); } function mysql_fetch_row($result){ return mysqli_fetch_row($result); } function mysql_query($query){ global $mysqli; return mysqli_query($mysqli,$query); } function mysql_escape_string($data){ global $mysqli; return mysqli_real_escape_string($mysqli, $data); } function mysql_real_escape_string($data){ return mysql_real_escape_string($data); } function mysql_close(){ global $mysqli; return mysqli_close($mysqli); } function mysql_num_rows($result){ return mysqli_num_rows($result); } } |
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (85)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (186)
- linux (143)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 低代码 (1)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)