PHP code example of hakuryo / database-client

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

    

hakuryo / database-client example snippets



$db = ConnectionDB::fromFile("my_file",'mydb');
$res = $db->search(request:"SELECT id,name,mail from user",trackBy:"mail");
print_r($res);
// Will ouptut something like this with id = 1 name=toto and [email protected]
Array
(
  ["[email protected]"] => stdClass Object
  (
      [id] => 1
      [name] => toto
      [mail] => [email protected]
  ) 
)




use hakuryo\db\ConnectionDB;
//Connection to mysql
$db = ConnectionDB::fromFile('config.ini', 'mysql');
//Usage of anonnymous params
$rq = "SELECT * FROM users";
// search function is for multiple result
print_r($db->search($rq, [1234]));
$db =null;

//Connection to oracle
$db = ConnectionDB::fromFile('config.ini', 'oracle');
$rq = "SELECT firstname FROM users WHERE id = :id";
//Usage of named params
// get function return the first line of the result
$result = $db->get($rq, ["id"=>1234]);

// Check if result is relevant
if($result !== null){
var_dump($result);
}
$db =null;

//Connection with a config.ini without section
$db = ConnectionDB::fromFile('config_without_section.ini');
$rq = "INSERT INTO users (firstname,lastname) VALUES (:fname,:lname)";
//Modify is use to perform update, insert or delete operation
print_r($db->modify($rq, ["fname"=>"Bob","lname"=>"Moran"]));
$db =null;