Commit a970270e authored by Freddy's avatar Freddy Committed by Luke081515

Add functions to DBcore

parent 1a38ed8e
Pipeline #1565 passed with stages
in 2 minutes and 36 seconds
......@@ -11,6 +11,7 @@ class DBCore extends DBPassword {
protected $db;
protected $loginHost;
private $dbPasswordVersion = "2.1.0"; // Should be the same as in DBPassword.php, when you are changing the file.
protected $result;
/** __construct
* Initializes the database connection
......@@ -61,18 +62,18 @@ class DBCore extends DBPassword {
* @return Returns the result, or 0 if you fetched an empty set.
*/
public function query($sql, $sensitive = false) {
$result = $this->db->query($sql);
if(!$result) {
$this->result = $this->db->query($sql);
if(!$this->result) {
$err = $this->db->error;
if ($sensitive === false) {
die("There was an error running the query [" . $err . "]");
} else {
echo ("\nThere was an error running the query [" . $err . "]");
}
} else if ($result->num_rows === 0) {
} else if ($this->result->num_rows === 0) {
return 0;
} else {
return $result;
return $this->result;
}
}
/** modify
......@@ -102,6 +103,34 @@ class DBCore extends DBPassword {
public function escape($string) {
return $this->db->real_escape_string($string);
}
/** fetchRow
* Fetch a single row and returns an array
* @author Freddy2001
*/
public function fetchRow() {
return $this->db->fetch_assoc();
}
/** fetchAllRows
* Fetch all rows and returns an array
* @author Freddy2001
*/
public function fetchAllRows() {
$array = array();
while ($row = $this->db->fetch_assoc()) {
$array[] = $row;
}
return $array;
}
/** count
* Counts number of rows
* @author Freddy2001
*/
public function count() {
if(is_resource($this->db) === true) {
$this->counter = $this->db->num_rows($this->result);
}
return $this->counter;
}
/** close
* Closes the connection
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment