dongweihuan8610 2017-04-08 04:25
浏览 124

mysqli :: __ construct()期望参数5为整数

I am trying to upload my website to a web hosting but i need phpmyadmin so i went to phpmyadmin.co with the username, password and server then when i tried to add that to my php file it came up with this error

mysqli::__construct() expects parameter 5 to be integer

this is the code of my website

<?php

class User{
private $dbServer   = "";
private $dbHost     = "http://www.phpmyadmin.co/";
private $dbUsername = "";
private $dbPassword = "";
private $dbName     = "sql12168044";
private $userTbl    = "users";

public function __construct(){
    if(!isset($this->db)){
        // Connect to the database
        $conn = new mysqli($this->dbHost, $this->dbServer, $this->dbUsername, $this->dbPassword, $this->dbName);
        if($conn->connect_error){
            die("Failed to connect with MySQL: " . $conn->connect_error);
        }else{
            $this->db = $conn;
        }
    }
}

/*
 * Returns rows from the database based on the conditions
 * @param string name of the table
 * @param array select, where, order_by, limit and return_type conditions
 */
public function getRows($conditions = array()){
    $sql = 'SELECT ';
    $sql .= array_key_exists("select",$conditions)?$conditions['select']:'*';
    $sql .= ' FROM '.$this->userTbl;
    if(array_key_exists("where",$conditions)){
        $sql .= ' WHERE ';
        $i = 0;
        foreach($conditions['where'] as $key => $value){
            $pre = ($i > 0)?' AND ':'';
            $sql .= $pre.$key." = '".$value."'";
            $i++;
        }
    }

    if(array_key_exists("order_by",$conditions)){
        $sql .= ' ORDER BY '.$conditions['order_by']; 
    }

    if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
        $sql .= ' LIMIT '.$conditions['start'].','.$conditions['limit']; 
    }elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
        $sql .= ' LIMIT '.$conditions['limit']; 
    }

    $result = $this->db->query($sql);

    if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){
        switch($conditions['return_type']){
            case 'count':
                $data = $result->num_rows;
                break;
            case 'single':
                $data = $result->fetch_assoc();
                break;
            default:
                $data = '';
        }
    }else{
        if($result->num_rows > 0){
            while($row = $result->fetch_assoc()){
                $data[] = $row;
            }
        }
    }
    return !empty($data)?$data:false;
}

/*
 * Insert data into the database
 * @param string name of the table
 * @param array the data for inserting into the table
 */
public function insert($data){
    if(!empty($data) && is_array($data)){
        $columns = '';
        $values  = '';
        $i = 0;
        if(!array_key_exists('created',$data)){
            $data['created'] = date("Y-m-d H:i:s");
        }
        if(!array_key_exists('modified',$data)){
            $data['modified'] = date("Y-m-d H:i:s");
        }
        foreach($data as $key=>$val){
            $pre = ($i > 0)?', ':'';
            $columns .= $pre.$key;
            $values  .= $pre."'".$val."'";
            $i++;
        }
        $query = "INSERT INTO ".$this->userTbl." (".$columns.") VALUES (".$values.")";
        $insert = $this->db->query($query);
        return $insert?$this->db->insert_id:false;
    }else{
        return false;
    }
}
}
  • 写回答

1条回答 默认 最新

  • dpwbc42604 2017-04-08 04:37
    关注

    You are passing the fifth parameter of the mysqli object as the $dbName, but that should be the $dbPort which is optional, and must be an integer. You have to reorganize your parameters to match this:

    mysqli::__construct ([ string $host = ini_get("mysqli.default_host") [,string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
    

    In order: $host, $username, $passwd, $dbname and $port. I don't see any room there for your $dbserver.

    UPDATE:

    Just use this:

    public function __construct(){
        if(!isset($this->db)){
            // Connect to the database
            $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
            if($conn->connect_error){
                die("Failed to connect with MySQL: " . $conn->connect_error);
            }else{
                $this->db = $conn;
            }
        }
    }
    

    And get rid of that $dbServer.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。