mysqli分离类从ajax请求调用返回空错误

时间:2015-02-25 10:20:06

标签: php ajax wordpress mysqli

我必须在我的php Wordpress插件中执行一些查询。所以我创建了一个seaprate类文件,我将逻辑存储在其中。

class Table{

static $host = 'localhost';
static $db_name = 'somedb';
static $db_username = 'someuser';
static $db_password = 'somepass';
private $table;
private $fields;

public function __construct($table, $fields){
    $this->db_name = $this->db_name;
    $this->host = $this->host;
    $this->db_password = db_password;
    $this->db_username = db_username;
    $this->table = $table;
    $this->fields = $fields;

}
public static function query($table, $fields){
    $mysqli = new mysqli(Table::$host,Table::db_username,Table::db_password,Table::db_name);
    if (mysqli_connect_errno($mysqli)) {
        return "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $fields = implode(",", $fields);
    $result = $mysqli->query("SELECT" . $fields . " from " . $table);
    while($row = $result->fetch_assoc()){
        $rows[] = $row;
    }
    $result->free();
    $mysqli->close();
    return $rows;
}

} ?>

然后我从这样的php文件中调用它:

$zips = Table::query("GeoPC_MA", array('city','zip'));

我从ajax请求调用最后一个文件,结果是500错误。但是我在开发者控制台日志中没有得到任何结果。

我想也许这与我实现Table类的方式有关。

请帮帮我

0 个答案:

没有答案
相关问题