$db -> statement>statement($sql, $param)
$db->statement("SELECT column_name FROM table WHERE = ?", "bind_me")
$db->statement("INSERT INTO table (col1, col2, col3) VALUES (?, ?, ?), [$foo, $bar, $baz]);
print_r($db -> result>result());
print json_encode($db -> result>result());
class Sqli
{
const DBHOST = "localhost";
const DBUSER = "";
const DBPASS = "";
const DBNAME = "";
protected $conn;
protected $stmt;
function __construct()
{
$this -> setConnection>setConnection();
}
private function setConnection()
{
mysqli_report(MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR);
try
{
$conn = new mysqli(
self::DBHOST,
self::DBUSER,
self::DBPASS,
self::DBNAME
);
}
catch(MySQLi_sql_exception $e)
{
throw new \MySQLi_sql_exception(
$e->getMessage(),
$e->getCode()
);
}
$this -> conn>conn = $conn;
}
public function statement($sql, $param)
{
$stmt = $this -> conn >conn-> prepare>prepare($sql);
if($param !== FALSE)
{
if(!is_array($param))
{
$param = [$param];
}
$types = str_repeat("s", count($param));
$stmt -> bind_param>bind_param($types, ...$param);
}
$stmt -> execute>execute();
$stmt -> store_result>store_result();
$this -> stmt>stmt = $stmt;
}
public function result()
{
$stmt = $this -> stmt;>stmt;
$meta = $stmt -> result_metadata>result_metadata();
while($field = $meta -> fetch_field>fetch_field())
{
$param[] = &$row[$field -> name];>name];
}
call_user_func_array([$stmt, "bind_result"], $param);
while($stmt -> fetch>fetch())
{
foreach($row as $key => $val)
{
$r[$key] = filter_var($val, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_LOW|FILTER_FLAG_ENCODE_AMP);
}
$result[] = $r;
}
return $result;
}
}