PHP code example of nulpunkt / yesql-php

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

    

nulpunkt / yesql-php example snippets


$pdo = new PDO($host, $user, $pass); // Fill in the blanks
$r = new Nulpunkt\Yesql\Repository($pdo, "my-queries/queries.sql");

$r->getAllRows();

// returns the insertId
$r->insertRow('a thing');

// returns the number of rows touched by the update
$r->updateRow(3, 'fixed thing');

// Fetches one row with id 3
$r->getById(3);

class MyObject {
  public static function mapRow($r) {
    return ['id' => $r['id'], 'ohwow' => $r['something']];
  }
}
// return one row, with keys id and ohwow
$r->getMappedById(3);

class MyObject {
}
// return one row, which is an instance of MyObject with id and something set
$r->getObjectById(3);

class MyObject {
  // $i will be the arguments passed to insertObject
  public static function toRow($i, $o) {
    return ['id' => $i, 'something' => $o->something];
  }
}
$o = new MyObject;
$r->insertObject($i, $o)

"nulpunkt/yesql-php": "^1"