gpt4 book ai didi

php - 如何修复 : Warning: mysqli_get_server_info() expects parameter 1 to be mysqli?

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:58 24 4
gpt4 key购买 nike

我的 PHP 非常糟糕,我正在尝试在我的主机上安装 arfoo.com。我在使用 mysql 和 mysqli 时遇到了一些问题,现在已修复。

但是现在我得到这个错误:

Warning: mysqli_get_server_info() expects parameter 1 to be mysqli, string given in /home/***/install/step4.php on line 47

对于下面的代码:

<?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');
}

非常感谢任何善意的帮助!

最佳答案

如果您想使用过程式风格,您应该将 mysqli_connect() 返回的对象作为参数传递给 mysqli_get_server_info()

$mysqlConnect = mysqli_connect("localhost", "my_user", "my_password");
$mysqlVersion = mysqli_get_server_info($mysqlConnect);

或者使用面向对象的风格:

$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;
}

关于php - 如何修复 : Warning: mysqli_get_server_info() expects parameter 1 to be mysqli?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com