Skip to content

Commit

Permalink
Merge pull request #6 from byjg/issue-5
Browse files Browse the repository at this point in the history
Issue 5
  • Loading branch information
byjg authored Jul 1, 2018
2 parents e329156 + f920454 commit 4116174
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/Connecting-to-MySQL-via-SSL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Connecting To MySQL via SSL

(Read here https://gist.github.com/byjg/860065a828150caf29c20209ecbd5692 about create server mysql)

```php
<?php
$sslCa = "/path/to/ca";
$sslKey = "/path/to/Key";
$sslCert = "/path/to/cert";
$sslCaPath = "/path";
$sslCipher = "DHE-RSA-AES256-SHA:AES128-SHA";
$verifySsl = 'false'; // or 'true'. Since PHP 7.1.

$db = \ByJG\AnyDataset\Factory::getDbRelationalInstance(
"mysql://localhost/database?ca=$sslCa&key=$sslKey&cert=$sslCert&capath=$sslCaPath&verifyssl=$verifySsl&cipher=$sslCipher"
);

$iterator = $db->getIterator('select * from table where field = :value', ['value' => 10]);
foreach ($iterator as $row) {
// Do Something
// $row->getField('field');
}
2 changes: 1 addition & 1 deletion example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require "vendor/autoload.php";

$db = new \ByJG\AnyDataset\Repository\DBDataset('mysql://root:aaaaaaa@10.10.10.101/development');
$db = \ByJG\AnyDataset\Factory::getDbRelationalInstance('mysql://root:aaaaaaa@localhost/development');

$iterator = $db->getIterator('select * from airports where idairports = [[idairports]]', ['idairports' => 898]);

Expand Down
24 changes: 24 additions & 0 deletions src/Store/PdoMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
class PdoMysql extends DbPdoDriver
{

protected $mysqlAttr = [
"ca" => PDO::MYSQL_ATTR_SSL_CA,
"capath" => PDO::MYSQL_ATTR_SSL_CAPATH,
"cert" => PDO::MYSQL_ATTR_SSL_CERT,
"key" => PDO::MYSQL_ATTR_SSL_KEY,
"cipher" => PDO::MYSQL_ATTR_SSL_CIPHER,
"verifyssl" => 1014 // PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT (>=7.1)
];

/**
* PdoMysql constructor.
*
Expand All @@ -25,6 +34,21 @@ public function __construct(Uri $connUri)
PDO::ATTR_EMULATE_PREPARES => true
];

if (!empty($connUri->getQuery())) {
foreach ($this->mysqlAttr as $key => $property) {
$value = $connUri->getQueryPart($key);
if (!empty($value)) {
$prepValue = urldecode($value);
if ($prepValue === 'false') {
$prepValue = false;
} else if ($prepValue === 'true') {
$prepValue = true;
}
$preOptions[$property] = $prepValue;
}
}
}

$this->setSupportMultRowset(true);

parent::__construct($connUri, $preOptions, $postOptions);
Expand Down

0 comments on commit 4116174

Please sign in to comment.