$data = $db->query('SELECT u.name, e.email FROM users u, email e WHERE u.id = e.user_id')
->feachAll(PDO::FETCH_GROUP);
foreach($data as $name => $user) {
echo "$name\n";
foreach($user as $i => $email) {
echo "\t$i. $email\n";
}
}
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);
}
echo "Format: $format. Config: $config->path. System (OS): $os.\n\n";
$db->query('insert into `messages` set ?u', $values);
SELECT значение FROM `table` WHERE id поста = 98 OR id поста = 54
$sql = 'INSERT INTO employees (first_name, second_name, middle_name, id_position) VALUES (?, ?, ?, ?)';
$pdo->prepare($sql)->execute([$_POST['f_name'], $_POST['s_name'], $_POST['m_name'], $_POST['list-position']]);
$stmt = $pdo->prepare("SELECT id, name, price, amount FROM table WHERE id = ?");
$stmt->execute([$id]);
$row = $stmt->fetch();
$stmt = $mysqli->prepare("SELECT id, name, price, amount FROM table WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->bind_result($id, $name, $price, $amount);
$stmt->execute();
$rows = array();
while ($stmt->fetch())
$rows[] = array(
'id' => $id;
'name' => $name;
'price' => $price;
'amount' => $amount;
);
}
$stmt = $pdo->prepare("SELECT * FROM table WHERE id = ?");
$stmt->execute([$id]);
$rows = $stmt->fetchAll();
$check->execute(array(":domainid" => $domainid , ":vhostid" => $vhostid, ":userid" => $login));
$mainname = $check->fetchColumn();
if ($mainname) {}
$connect = new PDO("mysql:host=127.0.0.1;dbname=***", "***", "***",[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index)
class article {
public function __construct($pdo)
$this->pdo = $pdo;
}
public function get_all_db() {
$sql = "SELECT `articles_id`, `title`, `keywords`, `description` FROM `articles`";
return $this->pdo->query($sql)->fetchAll();
}
public function get_one_db($id){
$sql = "SELECT `articles_id`, `title`, `keywords`, `description` FROM `articles` WHERE articles_id = ?";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([$id]);
return $stmt->fetch();
}
}
Удаленное подключение к Mysql является оправданным решением в разработке системы или же нет?
Подойдет ли Mysql для загруженных систем?
подкиньте литературу, у кого есть по этому направлению?