PHP code example of guinso / hx-db

1. Go to this page and download the library: Download guinso/hx-db 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/ */

    

guinso / hx-db example snippets




$pdo = new \PDO(...); //put standard parameter for PDO
$db = new \Hx\Db\SimpleDb($pdo);

//execute SQL
$sql = "SELECT * FROM account WHERE name = :name";
$pdoStatement = $db->runSql(
  $sql,
  array(":name" => "john")
);
foreach($row in $pdoStatement)
  //process each row data...

//execute SQl from file
$result = $db->runSqlFile("sql-script-file-path"); //only return number of affect row (Int)

//transaction
$db->BeginTransaction();
$db->CommitTransaction();
$db->RollBackTransaction(); //rollback

$pdo = new \PDO(...);
$sqlService = new \Hx\Db\SqlService(new \Hx\Db\SimpleDb($pdo));

//Select SQL
$sqlSelect = $sqlService->createSelectSql();
$sqlSelect->table("datatable-name a")
  ->column("a.name")
  ->column("a.address AS addr")
  ->where("a.age > :age")
  ->order("a.name DESC")
  ->group("a.nationality")
  ->join("INNER JOIN", "invoice b", "a.name = b.name")
  ->paginate(0, 10);
  
//to get sql script
$sqlScript = $sqlSelect->generateSql();

//to direct execute
$sqlStatement = $sqlSelect->execute(array(":age" => 18));