-2

Attempting to solve this issue. I'm trying to restore a extremely old version of Wordpress, back when it was known as B2, into a working state. After making a bunch of edits to the code in a attempt to get it working, I'm now getting this:

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in /home/Redacted/public_html/b2-include/b2functions.php on line 31

Here's the segment of the code that's having issues:

<?php

/* functions... */

function get_currentuserinfo() { // a bit like get_userdata(), on steroids
    global $HTTP_COOKIE_VARS,$user_login,$userdata,$user_level,$user_ID,$user_nickname,$user_email,$user_url,$user_pass_md5;
    // *** retrieving user's data from cookies and db - no spoofing
    $user_login = $HTTP_COOKIE_VARS["cafeloguser"];
    $userdata = get_userdatabylogin($user_login);
    $user_level = $userdata["user_level"];
    $user_ID=$userdata["ID"];
    $user_nickname=$userdata["user_nickname"];
    $user_email=$userdata["user_email"];
    $user_url=$userdata["user_url"];
    $user_pass_md5=md5($userdata["user_pass"]);
    $pref_usequicktags=$userdata["pref_usequicktags"];
    $pref_postnavigator=$userdata["pref_postnavigator"];
    $pref_showinactiveusers=$userdata["pref_showinactiveusers"];
    $pref_textarearows=$userdata["pref_textarearows"];
    $pref_confirm=$userdata["pref_confirm"];
    $pref_usespellchecker=$userdata["pref_usespellchecker"];
    // *** /retrieving
}


function dbconnect() {
    global $connexion, $server, $loginsql, $passsql, $base;

    $connexion = mysqli_connect($server,$loginsql,$passsql) or die("Couldn't connect! So sad :( <p>You should look into this!</p>");

    $connexionbase = mysqli_select_db($base) or die("Couldn't connect! So sad :( <p>You should look into this!</p>");

    return(($connexion && $connexionbase));
}

I am getting the error when I load the site at all. I can provide more code if necessary.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
John Doe
  • 1
  • 1
  • 2
  • can't you just check the manual entry for this kinds of errors? it already says `mysqli_select_db() expects exactly 2 parameters, 1 given` – Kevin Sep 30 '16 at 01:36

2 Answers2

2

Posting as a community wiki. I don't want rep from this and there shouldn't.

$connexionbase = mysqli_select_db($base)

Just as the error states. You need to pass the db connection as the first argument:

$connexionbase = mysqli_select_db($connexion, $base)

Reference:

Example from the manual:

bool mysqli_select_db ( mysqli $link , string $dbname )

Sidenote:

return(($connexion && $connexionbase));

TBH, I've never seen this type of syntax for a return. Far as I know, you can return only once or using an array.

Pulled from this answer https://stackoverflow.com/a/3815243/1415724

You can only return one value. But you can use an array that itself contains the other two values: return array($uid, $sid);

Instead of going through all that trouble, just use the 4 parameters:

$connexion = mysqli_connect($server,$loginsql,$passsql, $base)

as per the manual:

then return with and if it's really needed.

return $connexion;

Plus, why are you intending to use MD5 to store passwords with? That hashing function is no longer considered safe to use.

You're better off using password_hash().

This is the 21st century after all.

and $HTTP_COOKIE_VARS, that's deprecated.

I've no idea why you're using that code or where you got it from.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • just to add a note, most likely the OP is just testing if its connected, both boolean test for connection and the db itself, and covered in this answer, should have used `mysqli_connect` with 4 arguments (4th argument being the database name) – Kevin Sep 30 '16 at 01:59
  • @Ghost True yet it's really hard to say exactly what it's used for and they're also using the deprecated `$HTTP_COOKIE_VARS`, as noted in my answer along with a few other goodies ;-) – Funk Forty Niner Sep 30 '16 at 02:00
  • @Ghost However, that `return(($connexion && $connexionbase));` doesn't seem correct and I've made a note about it in the answer. – Funk Forty Niner Sep 30 '16 at 02:01
0

You need to pass the database name into your mysqli_select_db() function. Right now you're passing the connection improperly, you need to have that second parameter or it doesn't know what to do. Try updating it to this:

$connexionbase = mysqli_select_db(connexion, $base) ...
Matthew R.
  • 4,332
  • 1
  • 24
  • 39