1$host = 'localhost'; // URL to the server
2$user = 'root'; // Username (xampp = root)
3$pw = ''; // Password (xampp = )
4$dbname = 'database'; // The name of your database
5$dsn = "mysql:host=$host;dbname=$dbname";
6$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']; // If you want to use utf-8 use this line
7
8$db = new PDO($dsn, $user, $pw, $options); // Database Object
9$db -> setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // Use this if you want an associate array
10// $db -> setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); Use this if you want an indexed array
11
12$qry = 'select * from table;'; // Your query
13$result = $db -> query($qry); // execute query
14
15while ($row = $result -> fetch()) {
16 $id = $row[/*column-name*/];
17}