我有一个为php 5.3创建的PHP代码我需要使用它与php 5.6,所以需要将代码从mysql_转换为myspli_。请帮忙。
database.php的内容
<?php
$db_host = "localhost";
$db_username = "usr12345";
$db_password = "pass12345";
$database = "db12345";
?>
Php内容
// If database.php does not exist then print error
if (!include("database.php")) die("database.php could not be loaded!");
if ($db_host == "" || !isset($db_host)) die("please reinstall this panel");
//MySQL Verbindung wird getestet
$connection = mysql_connect($db_host, $db_username, $db_password) or die ("database could not be connected");
$db = mysql_select_db($database) or die ("database could not be selected");
// Logincheck
session_start();
// Language File check on DB
$captcha_sql = mysql_query("SELECT language FROM settings WHERE id='0'");
$language_setting = mysql_result($captcha_sql,0);
// Check if Language-file exists and include, else load English
if (file_exists("./pages/messages/".$language_setting.".php")) {
$language_setting = $language_setting;
}
else {
$errors[] = "<h2>The language file could not be found, English is the default language!</h2>";
$language_setting = "english";
}
include "./pages/messages/".$language_setting.".php";
// Get variable for include
if (!isset($_GET['include'])) {
$include_php = "main";
}
else {
$include_php = $_GET['include'];
}
答案 0 :(得分:0)
这应该可以正常工作:
function mysqli_result($res,$row=0,$col=0){
$numrows = mysqli_num_rows($res);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($res,$row);
$resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
if (isset($resrow[$col])){
return $resrow[$col];
}
}
return false;
}
// If database.php does not exist then print error
if (!include("database.php")) die("database.php could not be loaded!");
if ($db_host == "" || !isset($db_host)) die("please reinstall this panel");
//MySQL Verbindung wird getestet
$connection = mysqli_connect($db_host, $db_username, $db_password,$database) or die ("database could not be connected");
//$db = mysql_select_db($database) or die ("database could not be selected");
// Logincheck
session_start();
// Language File check on DB
$captcha_sql = mysqli_query($connection,"SELECT language FROM settings WHERE id='0'");
$language_setting = mysqli_result($captcha_sql,0);
// Check if Language-file exists and include, else load English
if (file_exists("./pages/messages/".$language_setting.".php")) {
$language_setting = $language_setting;
}
else {
$errors[] = "<h2>The language file could not be found, English is the default language!</h2>";
$language_setting = "english";
}
include "./pages/messages/".$language_setting.".php";
// Get variable for include
if (!isset($_GET['include'])) {
$include_php = "main";
}
else {
$include_php = $_GET['include'];
}