0

I'm very bad in PHP and I'm trying to install arfoo.com on my host. I had some problem with mysql and mysqli, which are fixed now.

But now I get this error:

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

For the following code:

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

?>

EDIT:

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

Any kind help is highly appreciated!

Kardo
  • 1,658
  • 4
  • 32
  • 52
  • 1
    Possible duplicate of [Warning: mysqli\_query() expects parameter 1 to be mysqli, null given in](http://stackoverflow.com/questions/18862743/warning-mysqli-query-expects-parameter-1-to-be-mysqli-null-given-in) – Henders Apr 19 '16 at 08:15

1 Answers1

4

You should pass the object returned by mysqli_connect() as argument to mysqli_get_server_info() if you want to use the procedural style.

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

Or using the OO style :

$mysqlConnect = new mysqli("localhost", "my_user", "my_password");
$mysqlVersion = $mysqlConnect->server_info;

See more at http://php.net/mysqli_get_server_info

EDIT :

Your dbConnect() function should return the mysqli object, try to add return $conn; at the end, like that :

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;
}
Aurel
  • 631
  • 3
  • 18
  • as dummie, I tried to do this: $mysqlConnect = dbConnect($_SESSION['mysqlServer'], $_SESSION['mysqlUser'], $_SESSION['mysqlPassword'], $_SESSION['mysqlDatabaseName'] ); $mysqlVersion = mysqli_get_server_info($mysqlConnect); but it didn't work – Kardo Apr 19 '16 at 08:27
  • Can you show me your `dbConnect()` function (edit your question to add it) ? – Aurel Apr 19 '16 at 08:28
  • I'd highly appreciate if you give me a code to copy and paste. I really no nothing about PHP :( – Kardo Apr 19 '16 at 08:28
  • I need to know what `dbConnect()` returns, try to find it in the included files (like **dbfunctions.php** or **createdb.php**) – Aurel Apr 19 '16 at 08:29
  • Add `return $conn;` at the end of the `dbConnect()` function, it should work. – Aurel Apr 19 '16 at 08:32
  • Thanks, but now I get this: Warning: mysqli_get_server_info() expects parameter 1 to be mysqli, null given in /install/step4.php on line 47 – Kardo Apr 19 '16 at 08:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109516/discussion-between-aurel-and-kardo). – Aurel Apr 19 '16 at 08:40