以下代码返回 500 错误,因为该代码在 php 版本 7 中折旧,如何使其在 php verison 7 中工作? [英] The following code returns an 500 error as the code is deprecited in php version 7, How to make it work in php verison 7?

查看:17
本文介绍了以下代码返回 500 错误,因为该代码在 php 版本 7 中折旧,如何使其在 php verison 7 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 php 版本 7 中使用但返回 500 错误的代码,我完全搞砸了要做什么,找不到任何文档来这样做.


' .mysql_error());}如果(!mysql_select_db(样本)){die('连接数据库时出错!<br><br>' .mysql_error());}//创建要运行的 MySQL 查询数组$sql = 数组('DROP TABLE IF EXISTS 内容;','CREATE TABLE content SELECT * FROM sample1.content');//运行 MySQL 查询如果 (sizeof($sql) > 0) {foreach ($sql as $query) {如果 (!mysql_query($query)) {die('发生了 MySQL 错误!<br><br>' .mysql_error());}}}mysql_close($con);?>

解决方案

这里有一个很好的教程,将废弃的 mysql_* PHP 代码转换为新的 mysqli_* 代码:

http://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html

在许多情况下,您只需为每个函数调用将mysql"更改为mysqli".

记得全部更改!

Here is the code that used but return the 500 error in php version 7 and I totally screwed what to do with and could not find any documentation to do so.

<?php
// Create a new MySQL database connection
if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' . mysql_error());
}

if (!mysql_select_db(sample)) {
die('An error occurred while connecting to the database!<br><br>' . mysql_error());
}

// Create an array of MySQL queries to run
$sql = array(
'DROP TABLE IF EXISTS content;',
'CREATE TABLE content SELECT * FROM sample1.content'
);

// Run the MySQL queries
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());
}
}
}

mysql_close($con);

?>

解决方案

Here's a good tutorial about converting deprecated mysql_* PHP code to new mysqli_* code:

http://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html

In many cases, you simply need to change "mysql" to "mysqli" for each function call.

Remember to change them all!

这篇关于以下代码返回 500 错误,因为该代码在 php 版本 7 中折旧,如何使其在 php verison 7 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆