dongqiancui9194 2016-10-18 20:19
浏览 222
已采纳

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.

  1. Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in
  2. /home4/purefic/public_html/demo/mytcg/settings.php on line 230
  3. Warning: mysqli_error() expects exactly 1 parameter, 0 given in
  4. /home4/purefic/public_html/demo/mytcg/settings.php on line 231
  5. 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)

  1. $users = array($user => md5($pass));
  2. $salt = substr(md5(date("F")), 8);
  3. $connect = mysqli_connect("$db_server", "$db_user", "$db_password")
  4. or die( DATABASE_CONNECT_ERROR . mysqli_error() );
  5. mysqli_select_db("$db_database" , $connect)
  6. or die( DATABASE_CONNECT_ERROR . mysqli_error() );
  7. function CleanUp($data) {
  8. $data = trim(htmlentities(strip_tags($data)));
  9. return $data;
  10. }
  11. function escape_sql($sql) {
  12. if (get_magic_quotes_gpc()) $sql = stripslashes($sql);
  13. return mysqli_real_escape_string($sql);
  14. }
  15. ?>
</div>

展开全部

  • 写回答

1条回答 默认 最新

  • duanpei8853 2016-10-18 20: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();
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部