From 89ca40cd646d78f9c979d018e93b67b2e9ab5ea0 Mon Sep 17 00:00:00 2001 From: Eduardo Malherbi Date: Thu, 24 May 2018 11:19:56 -0300 Subject: [PATCH] V1.0.7.2 --- README.md | 86 ++++++++++++++++++++++++++++++------------------- src/MyMssql.php | 18 +++++++++-- 2 files changed, 68 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e3980c3..d55a7f0 100755 --- a/README.md +++ b/README.md @@ -13,53 +13,73 @@ composer require emalherbi/mymssql ```php require_once 'vendor/autoload.php'; -// define timezone if not defined in ini file. -if (@date_default_timezone_get() !== @ini_get('date.timezone')) { - @date_default_timezone_set('America/Sao_Paulo'); -} +try { + // define timezone if not defined in ini file. + if (@date_default_timezone_get() !== @ini_get('date.timezone')) { + @date_default_timezone_set('America/Sao_Paulo'); + } + + $mssql = new MyMssql\MyMssql(array( + 'VERBOSE' => true, + 'ADAPTER' => 'SQLSRV', // or MSSQL + 'HOSTNAME' => '192.168.1.100', + 'USERNAME' => 'USERNAME', + 'PASSWORD' => 'PASSWORD', + 'DATABASE' => 'DATABASE', + ), realpath(dirname(__FILE__))); + + $row = $mssql->fetchRow('SELECT * FROM CLIENTES'); + echo '
';
+    echo print_r($row);
+    echo '
'; + + $all = $mssql->fetchAll('SELECT TOP 5 * FROM CLIENTES'); + echo '
';
+    echo print_r($all);
+    echo '
'; -$conn = array( - 'VERBOSE' => false, - 'ADAPTER' => 'SQLSRV', // or MSSQL - 'HOSTNAME' => '192.168.1.1', - 'USERNAME' => 'USERNAME', - 'PASSWORD' => 'PASSWORD', - 'DATABASE' => 'DATABASE', -); + $exec = $mssql->exec('UPDATE CLIENTES SET NOME = \'TESTE 123\' WHERE ID_CLIENTE = 450'); + echo '
';
+    echo print_r($exec);
+    echo '
'; -$log = realpath(dirname(__FILE__)); + $mssql->begin(); -$myMssql = new MyMssql\MyMssql($conn, $log); + $exec = $mssql->exec('UPDATE CLIENTES SET NOME = \'TESTE 456\' WHERE ID_CLIENTE = 450'); + echo '
';
+    echo print_r($exec);
+    echo '
'; -$result = $myMssql->fetchRow('SELECT * FROM TABLEX'); -echo '
';
-echo print_r($result);
-echo '
'; + $mssql->commit(); -$result = $myMssql->fetchAll('SELECT TOP 5 * FROM TABLEX'); -echo '
';
-echo print_r($result);
-echo '
'; + $mssqlsx = new MyMssql\MyMssqlSx(); -$result = $myMssql->exec('UPDATE TABLEX SET NAMEX=\'TESTE 000\' WHERE ID = 1'); -echo '
';
-echo print_r($result);
-echo '
'; + $sxName = 'SX_CLIENTES'; + $params = array(1, 385); + $result = $mssqlsx->fetchRowSx($sxName, $params); + echo '
';
+    echo print_r($result);
+    echo '
'; -try { - $myMssql->begin(); + $sxName = 'SX_CLIENTES'; + $params = array(2, 385); + $result = $mssqlsx->fetchAllSx($sxName, $params); + echo '
';
+    echo print_r($result);
+    echo '
'; - $result = $myMssql->exec('UPDATE TABLEX SET NAMEX=\'TEST 111\' WHERE ID = 2'); + $sxName = 'SX_SAVECLIENTES'; + $params = array(2, '2017-01-01', 385, 0, 0, 0, 0); + $result = $mssqlsx->execSx($sxName, $params); echo '
';
     echo print_r($result);
     echo '
'; - $myMssql->commit(); + echo 'Success...'; } catch (Exception $e) { - $myMssql->rollback(); + $mssql->rollback(); + die(print_r($e->getMessage())); } - -exit; ``` diff --git a/src/MyMssql.php b/src/MyMssql.php index 6b8d513..2f5a0f7 100755 --- a/src/MyMssql.php +++ b/src/MyMssql.php @@ -163,7 +163,11 @@ public function begin() $this->logger('MyMssql Begin Transaction'); } - $this->db->beginTransaction(); + if ('SQLSRV' === $this->ini['ADAPTER']) { + $this->db->beginTransaction(); + } else { + $this->logger('MyMssql Begin Transaction Only Works in SQLSRV ADAPTER'); + } } public function commit() @@ -174,7 +178,11 @@ public function commit() $this->logger('MyMssql Commit'); } - $this->db->commit(); + if ('SQLSRV' === $this->ini['ADAPTER']) { + $this->db->commit(); + } else { + $this->logger('MyMssql Commit Only Works in SQLSRV ADAPTER'); + } } public function rollback() @@ -185,7 +193,11 @@ public function rollback() $this->logger('MyMssql RollBack'); } - $this->db->rollBack(); + if ('SQLSRV' === $this->ini['ADAPTER']) { + $this->db->rollBack(); + } else { + $this->logger('MyMssql RollBack Only Works in SQLSRV ADAPTER'); + } } public function getIni()