dump db version
[openemr.git] / library / ADODB_mysqli_mod.php
blob45855a3370faec148237c645e1df2103a99e0c04
1 <?php
2 /**
3 * ADODB custom wrapper class to support ssl option in gacl and calendar.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 class ADODB_mysqli_mod extends ADODB_mysqli
14 // ADODB _connect function wrapper to work with OpenEMR
15 // Needed to do this to add support for mysql ssl.
16 // (so only have added the mysqli_ssl_set stuff)
17 // returns true or false
18 // To add: parameter int $port,
19 // parameter string $socket
20 function _connect(
21 $argHostname = null,
22 $argUsername = null,
23 $argPassword = null,
24 $argDatabasename = null,
25 $persist = false
26 ) {
27 if (!extension_loaded("mysqli")) {
28 return null;
30 $this->_connectionID = @mysqli_init();
32 if (is_null($this->_connectionID)) {
33 // mysqli_init only fails if insufficient memory
34 if ($this->debug) {
35 ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg());
37 return false;
40 I suggest a simple fix which would enable adodb and mysqli driver to
41 read connection options from the standard mysql configuration file
42 /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
44 foreach ($this->optionFlags as $arr) {
45 mysqli_options($this->_connectionID, $arr[0], $arr[1]);
48 //http ://php.net/manual/en/mysqli.persistconns.php
49 if ($persist && PHP_VERSION > 5.2 && strncmp($argHostname, 'p:', 2) != 0) {
50 $argHostname = 'p:'.$argHostname;
53 //Below was added by OpenEMR to support mysql ssl
54 // Note there is really weird behavior where the paths to certificates do not work if within a variable.
55 // (super odd which is why have 2 different mysqli_ssl_set commands as a work around)
56 if (defined('MYSQLI_CLIENT_SSL') && $this->clientFlags == MYSQLI_CLIENT_SSL) {
57 if (file_exists($GLOBALS['OE_SITE_DIR'] . "/documents/certificates/mysql-key") &&
58 file_exists($GLOBALS['OE_SITE_DIR'] . "/documents/certificates/mysql-cert")) {
59 // with client side certificate/key
60 mysqli_ssl_set(
61 $this->_connectionID,
62 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-key",
63 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-cert",
64 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-ca",
65 null,
66 null
68 } else {
69 // without client side certificate/key
70 mysqli_ssl_set(
71 $this->_connectionID,
72 null,
73 null,
74 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-ca",
75 null,
76 null
81 #if (!empty($this->port)) $argHostname .= ":".$this->port;
82 $ok = mysqli_real_connect(
83 $this->_connectionID,
84 $argHostname,
85 $argUsername,
86 $argPassword,
87 $argDatabasename,
88 # PHP7 compat: port must be int. Use default port if cast yields zero
89 (int)$this->port != 0 ? (int)$this->port : 3306,
90 $this->socket,
91 $this->clientFlags
94 if ($ok) {
95 if ($argDatabasename) {
96 return $this->SelectDB($argDatabasename);
98 return true;
99 } else {
100 if ($this->debug) {
101 ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
103 $this->_connectionID = null;
104 return false;