PHP Classes

File: read_all.php

Recommend this page to a friend!
  Packages of Channaveer Hakari   PHP PDO CRUD Example   read_all.php   Download  
File: read_all.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP PDO CRUD Example
Example code to implement CRUD operations with PDO
Author: By
Last change:
Date: 2 years ago
Size: 491 bytes
 

 

Contents

Class file image Download
<?php
require_once './db.php';

try {
    $userQuery = $pdo->prepare("
        SELECT 
            `id`, `first_name`, `last_name`, `email`, `password`
        FROM
            `users`
    ");
    $userQuery->execute();
    
    $users = $userQuery->fetchAll(PDO::FETCH_OBJ);

    if (!$users) {
        throw new Exception('User details not found');
    }

    echo '<pre>';
    print_r($users);
} catch (Exception $e) {
    /** Handle all your errors here */
    exit($e->getMessage());
}