I want to get all data from my database table 'user_info' with PDO in PHP. My username is 'root' and the database is name 'meta'.
How to connect to it with PDO with PHP.
CodePudding user response:
Try this:
<?php
$adr = 'localhost';
$dbn = 'meta';
$usr = 'root';
$pwd = 'password';
$pdo = new PDO("mysql:host=$adr;dbname=$dbn", $usr, $pwd);
$stmt = $pdo->prepare("SELECT * FROM table;");
$stmt->execute();
foreach ($stmt as $row) {
// Handle the $row content
}
?>