我在PHP中非常糟糕,我正在尝试在我的主机上安装arfoo.com。我有一些mysql和mysqli的问题,现在已修复。
但现在我收到了这个错误:
警告:mysqli_get_server_info()要求参数1为mysqli,第47行/home/***/install/step4.php中给出的字符串
以下代码:
<?php
/**
* Arfooo
*
* @package Arfooo
* @copyright Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en)
* by Guillaume Hocine (c) 2007 - 2010
* http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en)
* @author Guillaume Hocine & Adrian Galewski
* @license http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons
*/
session_start();
error_reporting(E_ALL);
require_once('languages/' . $_SESSION['selectedLanguage'] . '.php');
$chemin_includes_header = 'includes/';
include_once($chemin_includes_header.'header.php');
require_once("dbfunctions.php");
require_once("createdb.php");
function createDbConfig($dbHost, $dbUser, $dbPass, $dbName, $dbPrefix)
{
$dbConfig['DB_HOST'] = $dbHost;
$dbConfig['DB_USER'] = $dbUser;
$dbConfig['DB_PASS'] = $dbPass;
$dbConfig['DB_NAME'] = $dbName;
$dbConfig['DB_PREFIX'] = $dbPrefix;
$dbConfig['DB_INSTALLED'] = true;
$data = "<?php\n \$dbConfig = " . var_export($dbConfig, true). ";\n ?>";
file_put_contents("../config/db.php", $data);
}
$_SESSION['mysqlServer'] = $_POST['mysqlServer'];
$_SESSION['mysqlUser'] = $_POST['mysqlUser'];
$_SESSION['mysqlPassword'] = $_POST['mysqlPassword'];
$_SESSION['mysqlDatabaseName'] = $_POST['mysqlDatabaseName'];
$_SESSION['mysqlTablesPrefix'] = $_POST['mysqlTablesPrefix'];
dbConnect($_SESSION['mysqlServer'],
$_SESSION['mysqlUser'],
$_SESSION['mysqlPassword'],
$_SESSION['mysqlDatabaseName']
);
$mysqlVersion = mysqli_get_server_info();
$mysqlVersionCorrect = version_compare($mysqlVersion, "4.1", ">=");
if($mysqlVersionCorrect)
{
createDbConfig($_POST['mysqlServer'],
$_POST['mysqlUser'],
$_POST['mysqlPassword'],
$_POST['mysqlDatabaseName'],
$_POST['mysqlTablesPrefix']);
$tablesList = createDbTables($_POST['mysqlTablesPrefix'],
$_SESSION['siteRootUrl'],
$_SESSION['selectedLanguage'],
$_SESSION['urlRewriting']
);
}
else
{
$tablesList = array();
}
?>
编辑:
function dbConnect($server, $user, $pass, $dbName)
{
/* install database with prefixed tables */
$conn = mysqli_connect($server, $user, $pass, $dbName);
//mysql_connect($server, $user, $pass) or die('could not connect to mysql');;
mysqli_query($conn, 'CREATE TEMPORARY TABLE table');
//mysqli_query($dbName, 'CREATE TEMPORARY TABLE `table`');
//mysql_query('create database IF NOT EXISTS ' . $dbName);
mysqli_select_db($conn, $dbName) or die('could not select database');
}
非常感谢任何帮助!
答案 0 :(得分:3)
如果要使用程序样式,则应将mysqli_connect()
返回的对象作为参数传递给mysqli_get_server_info()
。
$mysqlConnect = mysqli_connect("localhost", "my_user", "my_password");
$mysqlVersion = mysqli_get_server_info($mysqlConnect);
或使用 OO风格:
$mysqlConnect = new mysqli("localhost", "my_user", "my_password");
$mysqlVersion = $mysqlConnect->server_info;
在http://php.net/mysqli_get_server_info
了解详情编辑:
您的dbConnect()函数应该返回mysqli对象,尝试在最后添加return $conn;
,如下所示:
function dbConnect($server, $user, $pass, $dbName)
{
/* install database with prefixed tables */
$conn = mysqli_connect($server, $user, $pass, $dbName);
//mysql_connect($server, $user, $pass) or die('could not connect to mysql');;
mysqli_query($conn, 'CREATE TEMPORARY TABLE table');
//mysqli_query($dbName, 'CREATE TEMPORARY TABLE `table`');
//mysql_query('create database IF NOT EXISTS ' . $dbName);
mysqli_select_db($conn, $dbName) or die('could not select database');
return $conn;
}