Connection is now using Gbili\Db\Req\Req underneath
This commit is contained in:
5
boot/bootstrap.php
Normal file
5
boot/bootstrap.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
use \Bsr\Utils\Configuration\Configuration;
|
||||||
|
use \Gbili\Db\Req\AbstractReq;
|
||||||
|
|
||||||
|
AbstractReq::generateAdapter(Configuration::get('db_req'));
|
||||||
@@ -13,10 +13,15 @@
|
|||||||
{
|
{
|
||||||
"type" : "vcs",
|
"type" : "vcs",
|
||||||
"url" : "https://usrpath@bitbucket.org/usrpath/bsrutils.git"
|
"url" : "https://usrpath@bitbucket.org/usrpath/bsrutils.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type" : "vcs",
|
||||||
|
"url" : "https://usrpath@bitbucket.org/usrpath/gbilidbreq.git"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require" : {
|
"require" : {
|
||||||
"bsr/utils" : "v2.0.1"
|
"bsr/utils" : "v2.0.1",
|
||||||
|
"gbili/dbreq" : "^0.0.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Bsr\\" : "src/"}
|
"psr-4": {"Bsr\\" : "src/"}
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ namespace Bsr\Db;
|
|||||||
|
|
||||||
use Bsr\Utils\Configuration\Configuration;
|
use Bsr\Utils\Configuration\Configuration;
|
||||||
use Bsr\Db\Exception\SqlException;
|
use Bsr\Db\Exception\SqlException;
|
||||||
|
use Gbili\Db\Req\Req;
|
||||||
|
|
||||||
class Connection
|
class Connection
|
||||||
{
|
{
|
||||||
// Internal variable to hold the connection
|
/**
|
||||||
private static $db;
|
* @var Gbili\Db\Req\Req
|
||||||
|
*/
|
||||||
final private function __construct() {}
|
private static $req;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $query
|
* @param $query
|
||||||
@@ -17,40 +18,20 @@ class Connection
|
|||||||
* @return OdbcResultSet|resource|string
|
* @return OdbcResultSet|resource|string
|
||||||
* @throws SqlException
|
* @throws SqlException
|
||||||
*/
|
*/
|
||||||
public static function execute($query, $throw_error = false)
|
public static function execute($sql, $values)
|
||||||
{
|
{
|
||||||
$result = odbc_exec(self::get(), utf8_decode($query));
|
if (null === self::$req) {
|
||||||
$result = new OdbcResultSet($result);
|
self::$req = new Req();
|
||||||
|
|
||||||
if ($result->is_error()) {
|
|
||||||
if($throw_error) {
|
|
||||||
throw new SqlException($result->get_error(), $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result->get_error();
|
|
||||||
}
|
}
|
||||||
|
return self::$req->getResultSet($sql, $values);
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PDO connection
|
||||||
|
*/
|
||||||
public static function get()
|
public static function get()
|
||||||
{
|
{
|
||||||
if (is_null(self::$db)) {
|
return self::$req->getAdapter();
|
||||||
$dsn = sprintf(
|
|
||||||
"Driver={%s};Server=%s,%s;Database=%s;",
|
|
||||||
Configuration::get('db.driver'),
|
|
||||||
Configuration::get('db.server'),
|
|
||||||
Configuration::get('db.port'),
|
|
||||||
Configuration::get('db.name')
|
|
||||||
);
|
|
||||||
self::$db = odbc_pconnect($dsn, Configuration::get('db.username'), Configuration::get('db.password'));
|
|
||||||
|
|
||||||
if (self::$db === false) {
|
|
||||||
throw new SqlException("Unable to connect to the server.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return the connection
|
|
||||||
return self::$db;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final private function __clone() {}
|
final private function __clone() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user