PHP code example of uk / db

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

    

uk / db example snippets


use UK\DB\Connection;

try
{

   // Open the PGSQL connection (for example)
   $conn = Connection::CreatePgSQL(
      '127.0.0.1',
      'my_database',
      'db_user',
      'db_password',
      'UTF8',
      5432
   );

   // Fetch all records with an foo value > 0
   $records = $conn->fetchAll(
      'SELECT foo, bar, baz from my_table WHERE foo > ?',
      [ 0 ]
   );

   // Output the returned records
   print_r( $records );

}
catch ( \Exception $ex )
{

   echo $ex;
   exit;

}

$records = $connectionInstance->fetchAll(
   // The SQL query string
   'SELECT foo, bar FROM my_table WHERE foo > ? ORDER BY foo {$ORDER_DIRECTION=ASC}',
   // Prepared statement parameters
   [ 0 ],
   \PDO::FETCH_ASSOC
   // The query vars
   [ 'ORDER_DIRECTION' => 'DESC' ]
);