PHP code example of sinri / sinri-database-agent

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

    

sinri / sinri-database-agent example snippets


// PDO
use sinri\SinriDatabaseAgent\SinriPDO;
$db=new SinriPDO($params);
// MySQLi
use sinri\SinriDatabaseAgent\SinriMySQLi;
$db=new SinriMySQLi($params);

$sql="SELECT X,Y FROM T WHERE KEY>0;";

$db->getAll($sql);
// return [["X"=>"x1","Y"=>"y1"],["X"=>"x2","Y"=>"y2"]]

$db->getRow($sql);
// return ["X"=>"x1","Y"=>"y1"]

$db->getCol($sql);
// return ["x1","x2"]

$db->getOne($sql);
// return "x1"

$sql="INSERT INTO...";
$db->insert($sql);
// return the last inserted record's PK value.

$sql="UPDATE ...";// or DELETE, etc.
$db->exec($sql);
// return affected row count, or FALSE on failure.

$db->beginTransaction();

// do some work

$db->inTransaction();
// return if this line is in transaction

if($has_error){
    $db->rollBack();
}else{
    $db->commit();
}