Skip to content

Commit

Permalink
V1.0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
emalherbi committed May 24, 2018
1 parent 03ef7b9 commit 89ca40c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 36 deletions.
86 changes: 53 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<pre>';
echo print_r($row);
echo '</pre>';

$all = $mssql->fetchAll('SELECT TOP 5 * FROM CLIENTES');
echo '<pre>';
echo print_r($all);
echo '</pre>';

$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 '<pre>';
echo print_r($exec);
echo '</pre>';

$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 '<pre>';
echo print_r($exec);
echo '</pre>';

$result = $myMssql->fetchRow('SELECT * FROM TABLEX');
echo '<pre>';
echo print_r($result);
echo '</pre>';
$mssql->commit();

$result = $myMssql->fetchAll('SELECT TOP 5 * FROM TABLEX');
echo '<pre>';
echo print_r($result);
echo '</pre>';
$mssqlsx = new MyMssql\MyMssqlSx();

$result = $myMssql->exec('UPDATE TABLEX SET NAMEX=\'TESTE 000\' WHERE ID = 1');
echo '<pre>';
echo print_r($result);
echo '</pre>';
$sxName = 'SX_CLIENTES';
$params = array(1, 385);
$result = $mssqlsx->fetchRowSx($sxName, $params);
echo '<pre>';
echo print_r($result);
echo '</pre>';

try {
$myMssql->begin();
$sxName = 'SX_CLIENTES';
$params = array(2, 385);
$result = $mssqlsx->fetchAllSx($sxName, $params);
echo '<pre>';
echo print_r($result);
echo '</pre>';

$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 '<pre>';
echo print_r($result);
echo '</pre>';

$myMssql->commit();
echo 'Success...';
} catch (Exception $e) {
$myMssql->rollback();
$mssql->rollback();

die(print_r($e->getMessage()));
}

exit;
```

18 changes: 15 additions & 3 deletions src/MyMssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 89ca40c

Please sign in to comment.