为什么升级到php7后我的用户注册页面不起作用

时间:2019-10-28 07:01:11

标签: php

最近我将服务器升级到PHP7,并且发现我的用户注册页面不起作用。

用户注册时,详细信息不会移到数据库中。

不确定这些代码在php 7上是否有效。

我试图修改脚本,但没有一个起作用。如果您能通过以下代码了解出了什么问题,我将不胜感激:

Script to connect to database    
<?php
class User{
private $host     = "localhost";
private $username = "xxxxx";
private $password = "xxxx";
private $name     = "xxxx";
private $table    = "user_account";

public function __construct(){
    if(!isset($this->db)){
        // Connect to the database
        $conn = new mysqli($this->host, $this->username, $this->password, 
$this->name);
        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
 */
public function getRows($conditions = array()){
    $sql = 'SELECT ';
    $sql .= array_key_exists("select",$conditions)? 
$conditions['select']:'*';
    $sql .= ' FROM '.$this->table;
    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
 */
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->table." (".$columns.") VALUES 
(".$values.")";
        $insert = $this->db->query($query);
        return $insert?$this->db->insert_id:false;
    }else{
        return false;
    }
}

/*
 * Update data into the database
 */
public function update($data, $conditions){
    if(!empty($data) && is_array($data) && !empty($conditions)){
        //prepare columns and values sql
        $cols_vals = '';
        $i = 0;
        if(!array_key_exists('modified',$data)){
            $data['modified'] = date("Y-m-d H:i:s");
        }
        foreach($data as $key=>$val){
            $pre = ($i > 0)?', ':'';
            $cols_vals .= $pre.$key." = '".$val."'";
            $i++;
        }

        //prepare where conditions
        $whereSql = '';
        $ci = 0;
        foreach($conditions as $key => $value){
            $pre = ($ci > 0)?' AND ':'';
            $whereSql .= $pre.$key." = '".$value."'";
            $ci++;
        }

        //prepare sql query
        $query = "UPDATE ".$this->table." SET ".$cols_vals." WHERE 
".$whereSql;

        //update data
        $update = $this->db->query($query);
        return $update?true:false;
    }else{
        return false;
    }
}

}
?>

0 个答案:

没有答案