Доброе утро!
[b]костыль[/b]
[php]
class MysqliEsc {
protected $link = null;
public function __construct($host, $user, $password, $database, $port = 3306, $socket = null) {
$this->link = new \mysqli
($host, $user, $password, $database, $port, $socket); }
/**
*
* @param string $sql sql запрос вида select * from таблица where поле = %s
* @param array $params Массив!!! с параметрами (параметром)
* @return \mysqli_result
*/
public function query
($sql, array $params = []) { if ($params) {
return $this->link->real_escape_string($param);
}));
}
return $this->link->query($sql);
}
}
Использование
$db = new MysqliEsc('localhost', 'root', '', 'silex');
var_dump($db->query('select * from users where id = %s', [1])->fetch_array());
вернет
[q]
array (size=22)
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string 'srv16rus@gmail.com' (length=18)
'email' => string 'srv16rus@gmail.com' (length=18)
2 => string 'HQZgK/c3tX6LXvqaPZowmQ+uyKtr4HjjMs9QMe6ZNYx6GHTa+hOV06N/tm7DSWqRFJLhiC+WySIVoZmnrzqGzg==' (length=88)
'password' => string 'HQZgK/c3tX6LXvqaPZowmQ+uyKtr4HjjMs9QMe6ZNYx6GHTa+hOV06N/tm7DSWqRFJLhiC+WySIVoZmnrzqGzg==' (length=88)
3 => string 'lapn8gh0q1ccww0so4g8k4oog80soc0' (length=31)
'salt' => string 'lapn8gh0q1ccww0so4g8k4oog80soc0' (length=31)
4 => string 'ROLE_USER' (length=9)
'roles' => string 'ROLE_USER' (length=9)
5 => string 'mmmmmmmmmmm' (length=11)
'name' => string 'mmmmmmmmmmm' (length=11)
6 => string '1419016035' (length=10)
'time_created' => string '1419016035' (length=10)
7 => null
'username' => null
8 => string '1' (length=1)
'isEnabled' => string '1' (length=1)
9 => null
'confirmationToken' => null
10 => null
'timePasswordResetRequested' => null
[/q][/php]