...
"autoload": {
"psr-4": {
"Fogersp\\SuperProject\\": "app"
}
},
...
composer dumpautoload
include '../vendor/autoload.php';
public function query($sql, $params = NULL){
$sth = $this->dbh->prepare($sql);
$sth->execute($params); // <----
return $sth;
}
$db->query("DELETE FROM t WHERE id=?", [$id]);
$count = $db->query("SELECT count(*) FROM t")->fetchColumn();
$list = $db->query("SELECT count(*) FROM t")->fetchAll(\PDO::FETCH_CLASS, "class");
public function listObjects($sql, $class, $params){
return $this->query($sql, $params)->fetchAll(\PDO::FETCH_CLASS, $class);
}
function db($query, $arr=false){
global $mysqli;
if(!$mysqli or isset($mysqli)){
$mysqli = new mysqli('localhost', 'user', '???', 'db');
$mysqli->set_charset("utf8");
}
$stmt = $mysqli->stmt_init();
if($stmt->prepare($query)){
if(is_array($arr)){
$refarg = array($stmt, str_pad('', count($arr), 's'));
foreach ($arr as $key => $value){
$refarg[] =& $arr[$key];
}
call_user_func_array("mysqli_stmt_bind_param", $refarg);
}
$stmt->execute();
$qb = $stmt->get_result();
if(preg_match("/select (.*)/i", $query)){
if(preg_match("/(.*) limit 1/i", $query)){
$result = mysqli_fetch_array($qb);
}else{
$result = array();
while($arr = mysqli_fetch_array($qb)){
$result[] = $arr;
}
}
}elseif(preg_match("/insert (.*)/i", $query)){
$result = $mysqli->insert_id;
}else{
$result = true;
}
$stmt->close();
}else{
$result = false;
}
return $result;
}
...$arr
вы не получите ключи в массиве. Поэтому почему бы не сделать третий агрумент обычным агрументом, и не передавать туда массив, который без изменений будет передаваться в execute?public function query($sql, $class, $params){ // $params = [":age"=>20]
$sth = $this->dbh->prepare($sql);
$res = $sth->execute($params); // <----
if (false !== $res) {
return $sth->fetchAll(\PDO::FETCH_CLASS, $class);
}
return [];
}
header('Location: /index.php');
Displays the details of shell extensions installed on your computer.
Disable/Enable items in the New submenu of Explorer.
Disable/enable static menu items in context menu of Explorer.