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