使用变量连接到db不能与mysql一起使用[复制]

This question already has an answer here:

Im trying to get modern and use mysqli like this

$connect = mysqli_connect($servername, $username, $password);
mysql_select_db($dbname);

but it dosent work,

This works

$connect = mysql_connect($servername, $username, $password);
mysql_select_db($dbname);

am i just tired or is it completly wrong?

</div>

The mistake is in your select database line, you did mix it with mysql_* when you should use mysqli_*

Your should use mysqli_select_db for selecting database using mysqli_* extension.

Your final code would be something like this:

$connect = mysqli_connect($servername, $username, $password);
mysqli_select_db($connect, $dbname);