diff --git a/docs/Connecting-to-MySQL-via-SSL.md b/docs/Connecting-to-MySQL-via-SSL.md new file mode 100644 index 0000000..8154f58 --- /dev/null +++ b/docs/Connecting-to-MySQL-via-SSL.md @@ -0,0 +1,22 @@ +# Connecting To MySQL via SSL + +(Read here https://gist.github.com/byjg/860065a828150caf29c20209ecbd5692 about create server mysql) + +```php +getIterator('select * from table where field = :value', ['value' => 10]); +foreach ($iterator as $row) { + // Do Something + // $row->getField('field'); +} diff --git a/example.php b/example.php index 0a10b60..e8d8079 100644 --- a/example.php +++ b/example.php @@ -1,7 +1,7 @@ getIterator('select * from airports where idairports = [[idairports]]', ['idairports' => 898]); diff --git a/src/Store/PdoMysql.php b/src/Store/PdoMysql.php index dd4b28e..bb930c2 100644 --- a/src/Store/PdoMysql.php +++ b/src/Store/PdoMysql.php @@ -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. * @@ -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);