shimabuku Posted January 20, 2020 Share Posted January 20, 2020 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); Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/ Share on other sites More sharing options...
requinix Posted January 20, 2020 Share Posted January 20, 2020 Were you able to find the parts in your existing where you call those two functions? Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573674 Share on other sites More sharing options...
ginerjm Posted January 20, 2020 Share Posted January 20, 2020 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573682 Share on other sites More sharing options...
shimabuku Posted January 20, 2020 Author Share Posted January 20, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573684 Share on other sites More sharing options...
requinix Posted January 20, 2020 Share Posted January 20, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573687 Share on other sites More sharing options...
shimabuku Posted January 22, 2020 Author Share Posted January 22, 2020 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); Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573724 Share on other sites More sharing options...
mac_gyver Posted January 22, 2020 Share Posted January 22, 2020 On 1/19/2020 at 5:51 PM, shimabuku said: error_reporting(0); the code is intentionally disabling error reporting via the above line. comment out that line and see what you get. Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573725 Share on other sites More sharing options...
shimabuku Posted January 22, 2020 Author Share Posted January 22, 2020 33 minutes ago, mac_gyver said: the code is intentionally disabling error reporting via the above line. comment out that line and see what you get. Roger that. I'll try that when I get home. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/309907-php-warning-mysqli_select_db-expects-exactly-2-parameters-1-given/#findComment-1573727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.