Fetching Data from a MySQL Database with PDO in PHP


Retrieve data from a MySQL database using PDO.

Source Code

$pdo = new PDO('mysql:host=localhost;dbname=testdb', 'username', 'password');
$stmt = $pdo->query("SELECT name FROM users");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo $row['name'] . "n";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments