1. Go to this page and download the library: Download osyra/syra 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/ */
osyra / syra example snippets
namespace App;
class CustomDatabase implements \Syra\DatabaseInterface {
private static
$writer,
$reader;
public static function getWriter() {
if(is_null(self::$writer)) {
self::$writer = new \Syra\MySQL\Database('hostname', 'user', 'password');
self::$writer->connect();
}
return self::$writer;
}
public static function getReader() {
if(is_null(self::$reader)) {
// if you have only one server
self::$reader = self::getWriter();
// if you have a slave for read only you could write this :
// self::$reader = new \Syra\MySQL\Database('ro-hostname', 'ro-user', 'ro-password');
// self::$reader->connect();
}
return self::$reader;
}
}
namespace App;
class CustomRequest extends \Syra\MySQL\Request {
const
DATABASE_CLASS = '\\App\\CustomDatabase';
protected function buildClassFromTable($table) {
return '\\App\\Model\\'.$table; // this must return the name of the class matched by the table
}
}