-
Notifications
You must be signed in to change notification settings - Fork 0
Query exec Method
Samuel Fajreldines edited this page Feb 28, 2018
·
1 revision
public function exec($sql='', $result_comparison_signal = '>', $fetch_all_rows = true){Class query exec method is responsible for executes a new SQL query.
- $sql - optional - SQL query to execute. If empty it'll use $this->sql.
- $result_comparison_signal - Comparison signal to verify if query was successfully executed. - See More
-
$fetch_all_rows -
- True - returns fetch parameter as an array with all results gotten.
- False - returns fetch parameter as the fetch_assoc correspondent method.
<?php
require_once('class_db.php');
$sql = new query(array(
'host' => 'localhost' ,
'user' => 'root' ,
'password' => '' ,
'database' => 'test' ,
'db_type' => 'mysqli' ,
));
$query = $sql->exec("SELECT * FROM users");
var_dump('Query result: ' . var_export($query->result,true));
var_dump($query);Returns
string(18) "Query result: true"
object(stdClass)#4 (8) {
["sql"]=>
string(19) "SELECT * FROM users"
["fetch"]=>
array(5) {
[0]=>
array(4) {
["idusers"]=>
string(1) "1"
["name"]=>
string(18) "0.5916307397108811"
["register_date"]=>
string(19) "2018-02-28 20:14:46"
["email"]=>
string(18) "0.5896094735615044"
}
[1]=>
array(4) {
["idusers"]=>
string(1) "2"
["name"]=>
string(19) "0.17315517940852343"
["register_date"]=>
string(19) "2018-02-28 20:14:48"
["email"]=>
string(17) "0.096947507091749"
}
[2]=>
array(4) {
["idusers"]=>
string(1) "3"
["name"]=>
string(18) "0.9652720279668198"
["register_date"]=>
string(19) "2018-02-28 20:15:05"
["email"]=>
string(18) "0.5355176492924967"
}
[3]=>
array(4) {
["idusers"]=>
string(1) "4"
["name"]=>
string(18) "0.7817721932956689"
["register_date"]=>
string(19) "2018-02-28 20:15:07"
["email"]=>
string(15) "0.3023080493345"
}
[4]=>
array(4) {
["idusers"]=>
string(1) "5"
["name"]=>
string(19) "0.16622369751913818"
["register_date"]=>
string(19) "2018-02-28 20:15:08"
["email"]=>
string(18) "0.9241943703258357"
}
}
["result"]=>
bool(true)
["object"]=>
object(mysqli_result)#3 (5) {
["current_field"]=>
int(0)
["field_count"]=>
int(4)
["lengths"]=>
NULL
["num_rows"]=>
int(5)
["type"]=>
int(0)
}
["num_rows"]=>
int(5)
["have_rows"]=>
bool(true)
["affected_rows"]=>
int(5)
["elapsed_time"]=>
int(0)
}
If we configure $result_comparison_signal to ">" and select a empty table:
<?php
require_once('class_db.php');
$sql = new query(array(
'host' => 'localhost' ,
'user' => 'root' ,
'password' => '' ,
'database' => 'test' ,
'db_type' => 'mysqli' ,
));
$query = $sql->exec("SELECT * FROM emprty_table",'>');
var_dump('Query result: ' . var_export($query->result,true));
var_dump($query);Returns
string(19) "Query result: false"
object(stdClass)#4 (8) {
["sql"]=>
string(26) "SELECT * FROM emprty_table"
["fetch"]=>
array(0) {
}
["result"]=>
bool(false)
["object"]=>
object(mysqli_result)#3 (5) {
["current_field"]=>
int(0)
["field_count"]=>
int(1)
["lengths"]=>
NULL
["num_rows"]=>
int(0)
["type"]=>
int(0)
}
["num_rows"]=>
int(0)
["have_rows"]=>
bool(false)
["affected_rows"]=>
int(0)
["elapsed_time"]=>
int(0)
}