John Doe John Doe - 22 days ago 4x
MySQL Question

mysqli_select_db() expects exactly 2 parameters, 1 given

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:


/* 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"];
// *** /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.


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)


Example from the manual:

bool mysqli_select_db ( mysqli $link , string $dbname )


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

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.