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 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题