php - mysqli_select_db() expects parameter 1 to be mysqli, array given -


i need to convert project mysql mysqlii ,but have problem in config file, please error in code?

<?php   $db = array (   "hostname"=>"localhost",    "dbname"=>"prstitodb",   "dbuser"=>"root",   "dbpass"=>"",          );     $dbconnect = mysqli_connect($db['hostname'],$db['dbuser'],$db['dbpass']) or die(mysqli_error());     $dbselect = mysqli_select_db($db,['dbname']) or die(mysqli_error());   ?> 

mysqli_select_db asked 2 parameters in first parameter connection object , provided 1 parameter , array :-

$dbselect = mysqli_select_db($db,['dbname']) or die(mysqli_error());  

, need remove first , provide $dbconnect first parameter

to resolve error, simplify code in 1 line below:-

<?php    $dbconnect = mysqli_connect('localhost','root','','prstitodb') or die(mysqli_error()); ?> 

but if still want go way remove , , it's ok

<?php   $db = array (   "hostname"=>"localhost",    "dbname"=>"prstitodb",   "dbuser"=>"root",   "dbpass"=>"",          );     $dbconnect = mysqli_connect($db['hostname'],$db['dbuser'],$db['dbpass']) or die(mysqli_error());     $dbselect = mysqli_select_db($dbconnect,$db['dbname']) or die(mysqli_error($dbconnect)); // remove `,` , provide connection object first parameter  ?> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -