mysqli_select_db() expects parameter 1 to be mysqli on line 8

自古美人都是妖i 提交于 2019-12-31 07:39:22

问题


I Don't know what actually I should do and if there is something wrong somebody please correct it and give it thanks in advance

<?php
    $db_host = 'localhost';
    $db_user = 'root';
    $db_pass = '';
    $db_name = 'cms';

    $conn = mysqli_connect($db_host,$db_user,$db_pass) or die(mysql_error());
        mysqli_select_db($db_name,$conn);

?>

回答1:


Use this:

$con = mysqli_connect($hostname,$user,$password,$database);

You don't need:

mysqli_select_db

Your code will be:

$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'cms';

$con = mysqli_connect($db_host,$db_user,$db_pass,$db_name);



回答2:


Why you trying use longest way? Instead, try:

$con=mysqli_connect('localhost', 'root', '', 'cms');



回答3:


Try this:

 mysqli_select_db($conn, $db_name);


来源:https://stackoverflow.com/questions/21498356/mysqli-select-db-expects-parameter-1-to-be-mysqli-on-line-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!