Update database.php

Add database -> select method.
This commit is contained in:
FusionPBX
2016-11-02 12:31:59 -06:00
committed by GitHub
parent cb96213e3d
commit 76edd90efd

View File

@@ -533,6 +533,45 @@ include "root.php";
unset($prep_statement);
} //count
public function select($sql) {
//connect to the database if needed
if (!$this->db) {
$this->connect();
}
//execute the query, and return the results
try {
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$message["message"] = "OK";
$message["code"] = "200";
$message["details"][$m]["name"] = $this->name;
$message["details"][$m]["message"] = "OK";
$message["details"][$m]["code"] = "200";
if ($this->debug["sql"]) {
$message["details"][$m]["sql"] = $sql;
}
$this->message = $message;
$this->result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset($prep_statement);
$m++;
return $this;
}
catch(PDOException $e) {
$message["message"] = "Bad Request";
$message["code"] = "400";
$message["details"][$m]["name"] = $this->name;
$message["details"][$m]["message"] = $e->getMessage();
$message["details"][$m]["code"] = "400";
if ($this->debug["sql"]) {
$message["details"][$m]["sql"] = $sql;
}
$this->message = $message;
$this->result = '';
$m++;
return $this;
}
} //select
public function find_new() {
//connect to the database if needed