Skip to content
Advertisement

How to connet to my database with pdo in php

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.

Advertisement

Answer

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
}
?>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement