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

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();
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置