Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
}
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading