File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Connecting To MySQL via SSL
2
+
3
+ (Read here https://gist.github.com/byjg/860065a828150caf29c20209ecbd5692 about create server mysql)
4
+
5
+ ``` php
6
+ <?php
7
+ $sslCa = "/path/to/ca";
8
+ $sslKey = "/path/to/Key";
9
+ $sslCert = "/path/to/cert";
10
+ $sslCaPath = "/path";
11
+ $sslCipher = "DHE-RSA-AES256-SHA:AES128-SHA";
12
+ $verifySsl = 'false'; // or 'true'. Since PHP 7.1.
13
+
14
+ $db = \ByJG\AnyDataset\Factory::getDbRelationalInstance(
15
+ "mysql://localhost/database?ca=$sslCa&key=$sslKey&cert=$sslCert&capath=$sslCaPath&verifyssl=$verifySsl&cipher=$sslCipher"
16
+ );
17
+
18
+ $iterator = $db->getIterator('select * from table where field = :value', ['value' => 10]);
19
+ foreach ($iterator as $row) {
20
+ // Do Something
21
+ // $row->getField('field');
22
+ }
Original file line number Diff line number Diff line change 1
1
<?php
2
2
require "vendor/autoload.php " ;
3
3
4
- $ db = new \ByJG \AnyDataset \Repository \ DBDataset ('mysql://root:aaaaaaa@10.10.10.101 /development ' );
4
+ $ db = \ByJG \AnyDataset \Factory:: getDbRelationalInstance ('mysql://root:aaaaaaa@localhost /development ' );
5
5
6
6
$ iterator = $ db ->getIterator ('select * from airports where idairports = [[idairports]] ' , ['idairports ' => 898 ]);
7
7
Original file line number Diff line number Diff line change 8
8
class PdoMysql extends DbPdoDriver
9
9
{
10
10
11
+ protected $ mysqlAttr = [
12
+ "ca " => PDO ::MYSQL_ATTR_SSL_CA ,
13
+ "capath " => PDO ::MYSQL_ATTR_SSL_CAPATH ,
14
+ "cert " => PDO ::MYSQL_ATTR_SSL_CERT ,
15
+ "key " => PDO ::MYSQL_ATTR_SSL_KEY ,
16
+ "cipher " => PDO ::MYSQL_ATTR_SSL_CIPHER ,
17
+ "verifyssl " => 1014 // PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT (>=7.1)
18
+ ];
19
+
11
20
/**
12
21
* PdoMysql constructor.
13
22
*
@@ -25,6 +34,21 @@ public function __construct(Uri $connUri)
25
34
PDO ::ATTR_EMULATE_PREPARES => true
26
35
];
27
36
37
+ if (!empty ($ connUri ->getQuery ())) {
38
+ foreach ($ this ->mysqlAttr as $ key => $ property ) {
39
+ $ value = $ connUri ->getQueryPart ($ key );
40
+ if (!empty ($ value )) {
41
+ $ prepValue = urldecode ($ value );
42
+ if ($ prepValue === 'false ' ) {
43
+ $ prepValue = false ;
44
+ } else if ($ prepValue === 'true ' ) {
45
+ $ prepValue = true ;
46
+ }
47
+ $ preOptions [$ property ] = $ prepValue ;
48
+ }
49
+ }
50
+ }
51
+
28
52
$ this ->setSupportMultRowset (true );
29
53
30
54
parent ::__construct ($ connUri , $ preOptions , $ postOptions );
You can’t perform that action at this time.
0 commit comments