PHP
3
Вклад в тег
$host = 'localhost';
$database = 'dbname';
$user = 'user';
$pass = 'root';
$dsn = "mysql:host=$host;dbname=$database;";
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn, $user, $pass, $options);
function user() {
global $pdo;
$stmt = $pdo->query('SELECT * FROM users');
$data = $stmt->fetchAll();
return $data;
}
$datas = user();
var_dump($datas);
$stmt = $pdo->query('SELECT * FROM users');
$data = $stmt->fetchAll();