dongqiancui9194 2016-10-19 04:19
浏览 221
已采纳

mysqli_select_db()期望参数1为mysqli,给定字符串&mysqli_error()需要1个参数,0在DATABASE_CONNECT_ERROR [duplicate]中给出

Ive searched on here and various other places and I just cannot find the answer to solve this problem. I just bought new hosting and am trying to move my sites. I am getting the error below.

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in
/home4/purefic/public_html/demo/mytcg/settings.php on line 230

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
/home4/purefic/public_html/demo/mytcg/settings.php on line 231
DATABASE_CONNECT_ERROR

And this is the coding I have on my settings page (originally working just fine on my old host I had everything as mysql and not mysqli like my research seemed to tell me to change to but as you can see it didnt work)

$users = array($user => md5($pass));
$salt = substr(md5(date("F")), 8);

$connect = mysqli_connect("$db_server", "$db_user", "$db_password")
    or die( DATABASE_CONNECT_ERROR . mysqli_error() );
mysqli_select_db("$db_database" , $connect)
    or die( DATABASE_CONNECT_ERROR . mysqli_error() );

function CleanUp($data) {
    $data = trim(htmlentities(strip_tags($data)));
    return $data;
    }

function escape_sql($sql) {
    if (get_magic_quotes_gpc()) $sql = stripslashes($sql);
    return mysqli_real_escape_string($sql);
    }
?>
</div>
  • 写回答

1条回答 默认 最新

  • duanpei8853 2016-10-19 04:47
    关注

    First of all you no need to have "" for your DB connection because you pass it as a variable

    Second thing is In MYSQLI always Pass $connection with your Connection.

    And for a mysqli_error pass $connection to let server know you are looking for error in Database Connection.

    Try this.

    $connect = mysqli_connect($db_server, $db_user, $db_password)
        or die( DATABASE_CONNECT_ERROR . mysqli_error($connect) );
    mysqli_select_db($connect, $db_database)
        or die( DATABASE_CONNECT_ERROR . mysqli_error($connect) );
    

    Edit

    either way you can try connect your DB As follow

    $connect = mysqli_connect($db_server, $db_user, $db_password, $db_database);
    
    // If no connection than Print error
    if (mysqli_connect_errno())
      {
          echo "No Active DB Connection Please check: " . mysqli_connect_error();
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历