PHP code example of pardnchiu / sql

1. Go to this page and download the library: Download pardnchiu/sql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pardnchiu / sql example snippets




use PD\SQL;

$result_user_0 = SQL::table('users')
   ->where("status", "active")
   ->where("age", ">", 18)
   ->get();

$result_order = SQL::table("orders")
   ->select("orders.*", "users.name")
   ->join("users", "orders.user_id", "users.id")
   ->where("orders.status", "pending")
   ->get();

$result_product = SQL::table("products")
   ->total()
   ->limit(10)
   ->offset(0)
   ->order_by("created_at", "DESC")
   ->get();

$result_user_1 = SQL::query(
    "SELECT * FROM users WHERE status = ? AND role = ?",
    ["active", "admin"]
);

try {
    $result = SQL::table("users")
        ->where("id", 1)
        ->update([
            "status" => "active",
            "updated_at" => "NOW()"
        ]);

    if (!empty($result["info"])) {
        echo "Performance: " . $result["info"];
    };
} catch (\PDOException $e) {
    echo "Database Error: " . $e->getMessage();
} catch (\Exception $e) {
    echo "General Error: " . $e->getMessage();
};