-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
841 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
composer.lock | ||
vendor/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
$header = <<<'EOF' | ||
Eduardo Malherbi Martins (http://emalherbi.com/) | ||
Copyright @emm | ||
Full Stack Web Developer. | ||
EOF; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PHP56Migration' => true, | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'array_syntax' => ['syntax' => 'long'], | ||
'combine_consecutive_unsets' => true, | ||
'general_phpdoc_annotation_remove' => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'], | ||
'header_comment' => ['header' => $header], | ||
'heredoc_to_nowdoc' => true, | ||
'list_syntax' => ['syntax' => 'long'], | ||
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'], | ||
'no_short_echo_tag' => true, | ||
'no_unreachable_default_argument_value' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'ordered_class_elements' => true, | ||
'ordered_imports' => true, | ||
'php_unit_strict' => true, | ||
'php_unit_test_class_requires_covers' => true, | ||
'phpdoc_add_missing_param_annotation' => true, | ||
'phpdoc_order' => true, | ||
'semicolon_after_instruction' => true, | ||
'strict_comparison' => false, | ||
'strict_param' => false, | ||
'dir_constant' => false, | ||
'native_function_invocation' => false, | ||
'native_constant_invocation' => false, | ||
]) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->exclude('tests/Fixtures') | ||
->in(__DIR__) | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,135 @@ | ||
# MyMssql | ||
|
||
Teste | ||
My Mssql PDO (MSSQL or SQLSRV) | ||
|
||
# Install | ||
|
||
``` | ||
composer require emalherbi/mymssql | ||
``` | ||
|
||
# Usage | ||
|
||
```php | ||
require_once 'vendor/autoload.php'; | ||
|
||
try { | ||
$mssql = new MyMssql\MyMssql(array( | ||
'VERBOSE' => true, | ||
'ADAPTER' => 'SQLSRV', // or MSSQL | ||
'HOSTNAME' => '192.168.1.100', // or 192.168.1.100\\SQL2016 | ||
'USERNAME' => 'USERNAME', | ||
'PASSWORD' => 'PASSWORD', | ||
'DATABASE' => 'DATABASE', | ||
), realpath(dirname(__FILE__)), 'UTF-8'); // Ex.: ISO-8859-1 | ||
|
||
$mssql->connect(); | ||
|
||
$mssql->disconnect(); | ||
|
||
$result = $mssql->getAdapter(); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->getIni(); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->isConnect(); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->fetchOne('SELECT * FROM CLIENTES'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->fetchRow('SELECT * FROM CLIENTES'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->fetchAll('SELECT TOP 5 * FROM CLIENTES'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->exec('UPDATE CLIENTES SET NOME = \'TESTE 123\' WHERE ID_CLIENTE = 450'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
// OR | ||
|
||
$result = $mssql->execSql('UPDATE CLIENTES SET NOME = \'TESTE 123\' WHERE ID_CLIENTE = 450'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$mssql->begin(); | ||
|
||
$result = $mssql->exec('UPDATE CLIENTES SET NOME = \'TESTE 456\' WHERE ID_CLIENTE = 450'); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$mssql->commit(); | ||
|
||
$sxName = 'SX_CLIENTES'; | ||
$params = array(1, 385); | ||
$result = $mssql->fetchRowSx($sxName, $params); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$sxName = 'SX_CLIENTES'; | ||
$params = array(2, 385); | ||
$result = $mssql->fetchAllSx($sxName, $params); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$sxName = 'SX_CLIENTES_SAVE'; | ||
$params = array(2, '2017-01-01', 385, 0, 0, 0, 0); | ||
$result = $mssql->execSx($sxName, $params); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$result = $mssql->exec("IF OBJECT_ID('USUARIOS') IS NULL | ||
BEGIN | ||
CREATE TABLE [dbo].[USUARIOS] | ||
( | ||
[ID_USUARIOS] [INT] IDENTITY(1,1) NOT NULL, | ||
[NOME] VARCHAR(100) NOT NULL, | ||
PRIMARY KEY CLUSTERED | ||
([ID_USUARIOS] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | ||
) ON [PRIMARY] | ||
END"); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$sql = " BEGIN DECLARE @REF INT SET @REF = NULL EXEC SX_TESTE @REF OUTPUT SELECT @REF AS REF END "; | ||
$result = $mssql->execScript($sql); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
$sql = " BEGIN DECLARE @REF INT SET @REF = NULL EXEC SX_TESTE @REF OUTPUT SELECT @REF AS REF END "; | ||
$isObject = false; // Array or Object Result | ||
$result = $mssql->execScriptResult($sql, $isObject); | ||
echo '<pre>'; | ||
echo print_r($result); | ||
echo '</pre>'; | ||
|
||
echo 'Success...'; | ||
} catch (Exception $e) { | ||
$mssql->rollback(); | ||
|
||
die(print_r($e->getMessage())); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "emalherbi/mymssql", | ||
"description": "My Mssql Pdo (MSSQL or SQLSRV)", | ||
"license": "MIT", | ||
"type": "library", | ||
"homepage": "https://github.com/emalherbi/MyMssql", | ||
"require": { | ||
"php": ">= 5.0.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MyMssql\\": "src" | ||
} | ||
} | ||
} |
Oops, something went wrong.