Jump to content

PHP Warning: mysqli_select_db() expects exactly 2 parameters, 1 given


Recommended Posts

Hello all! New here and new to PHP. I have an old script that was built for PHP 5.X and need some help getting it to work with PHP 7.X. According to the PHP manual I need to pass the db connection as the first argument. I do get the display error "SQL Error: Can't select DB" and in the logs show "PHP Warning:  mysqli_select_db() expects exactly 2 parameters, 1 given".

<?php
extract($_REQUEST);

$DB_HOST="localhost";                           //Host
$DB_DATABASE="babyyoda";                        //database name
$DB_USER="mando";                                //database username
$DB_PASSWORD="password";                              //databse password



$ADMIN_EMAIL='admin@example.com';
$TEMPLATES='./templates/';

$URL_BASE='http://example.com/banners/';

$PATH='/var/www/vhosts/example.com/httpdocs/banners/';  
$BANNERS_PATH=$PATH.'banners/';  
$BANNERS_URL=$URL_BASE.'banners/';  


$DB_TABLE_CATEGORIES='ban_categories';
$DB_TABLE_SUBCATEGORIES='ban_subcategories';
$DB_TABLE_SUBCATEGORIES_BANNERS='ban_subcategories_banners';
$DB_TABLE_BANNERS='ban_banners';
$DB_TABLE_USERS='ban_users';
$DB_TABLE_SETTINGS='ban_settings';

$IMAGE_MAGICK_PATH='/usr/bin/';
//$IMAGE_MAGICK_PATH='/usr/local/bin/';  	// on some servers it may be like this


$TEMPLATE_EXECUTE_PHP=1; // set to 1 to allow use of php inside of templates


$CRYPT_SALT='ef&dF%HGRTSvsw35';


$TYPES[1]='Jpeg';
$TYPES[2]='Gif';
$TYPES[3]='Flash'; // dont change flash should be "3"


//$LINKED_SCRIPTS['Galleries Manager']='/galleries/admin/';
//$LINKED_SCRIPTS['Flash Manager']='/flash/admin/';


$NATS=0;
//$PASS_VARIABLES=array('campaign','program');



define('CONFIG_INCLUDED',1);

mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("SQL ERROR: Can't Connect to DB");
mysqli_select_db($DB_DATABASE) or die("SQL ERROR: Can't select DB");


error_reporting(0);
ini_set('session.gc_maxlifetime',3600);

?>

 

I came up with the below but I don't know where to insert these two statements and what to remove.

$link = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
mysqli_select_db($link, $DB_DATABASE);

 

Needing 2 parms means that your connect didn't provide the proper result for the select_db call.  Figure out first why your connection fails.  Usually a good thing to check whenever you open a db connection.

if ($mysqli->connect_errno)
{
	echo "Connect failed, error is: " . $mysqli->connect_error);
	exit();
}

 

The original parts were;

mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("SQL ERROR: Can't Connect to DB");
mysql_select_db($DB_DATABASE) or die("SQL ERROR: Can't select DB");

So i figured I'd just change it to mysqli_connect and mysqli_select_db since it's PHP7.X.

1 hour ago, shimabuku said:

The original parts were;


mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("SQL ERROR: Can't Connect to DB");
mysql_select_db($DB_DATABASE) or die("SQL ERROR: Can't select DB");

So i figured I'd just change it to mysqli_connect and mysqli_select_db since it's PHP7.X.

Okay... I know you figured out the parameters because you posted what it should be, and now I know you have seen where those functions (which already have the "i" added) are in the code.

So what's the problem?

On 1/20/2020 at 10:15 AM, requinix said:

Okay... I know you figured out the parameters because you posted what it should be, and now I know you have seen where those functions (which already have the "i" added) are in the code.

So what's the problem?

When I change it to below. I just get an internal 500 error. Nothing in the logs.

$link = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
mysqli_select_db($link, $DB_DATABASE);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.