3 * ADODB custom wrapper class to support ssl option in main.
6 * @link http://www.open-emr.org
7 * @author Kevin Yeh <kevin.y@integralemr.com>
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_log
extends ADODB_mysqli
16 * ADODB Execute function wrapper to ensure proper auditing in OpenEMR.
18 * @param string $sql query
19 * @param array $inputarr binded variables array (optional)
20 * @return boolean returns false if error
22 function Execute($sql, $inputarr = false)
24 $retval= parent
::Execute($sql, $inputarr);
25 if ($retval === false) {
27 // Stash the error into last_mysql_error so it doesn't get clobbered when
28 // we insert into the audit log.
29 $GLOBALS['last_mysql_error']=$this->ErrorMsg();
32 $GLOBALS['last_mysql_error_no']=$this->ErrorNo();
37 // Stash the insert ID into lastidado so it doesn't get clobbered when
38 // we insert into the audit log.
39 $GLOBALS['lastidado']=$this->Insert_ID();
40 auditSQLEvent($sql, $outcome, $inputarr);
45 * ADODB Execute function wrapper to skip auditing in OpenEMR.
47 * Bypasses the OpenEMR auditing engine.
49 * @param string $sql query
50 * @param array $inputarr binded variables array (optional)
51 * @return boolean returns false if error
53 function ExecuteNoLog($sql, $inputarr = false)
55 return parent
::Execute($sql, $inputarr);
59 * ADODB GenID function wrapper to work with OpenEMR.
61 * Need to override to fix a bug where call to GenID was updating
62 * sequences table but always returning a zero with the OpenEMR audit
63 * engine both on and off. Note this bug only appears to occur in recent
64 * php versions on windows. The fix is to use the ExecuteNoLog() function
65 * rather than the Execute() functions within this function (otherwise,
66 * there are no other changes from the original ADODB GenID function).
68 * @param string $seqname table name containing sequence (default is adodbseq)
69 * @param integer $startID id to start with for a new sequence (default is 1)
70 * @return integer returns the sequence integer
72 function GenID($seqname = 'adodbseq', $startID = 1)
74 // post-nuke sets hasGenID to false
75 if (!$this->hasGenID
) {
79 $getnext = sprintf($this->_genIDSQL
, $seqname);
80 $holdtransOK = $this->_transOK
; // save the current status
81 $rs = @$this->ExecuteNoLog($getnext);
84 $this->_transOK
= true; //if the status was ok before reset
87 $u = strtoupper($seqname);
88 $this->ExecuteNoLog(sprintf($this->_genSeqSQL
, $seqname));
89 $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL
, $seqname));
91 $this->ExecuteNoLog(sprintf($this->_genSeq2SQL
, $seqname, $startID-1));
94 $rs = $this->ExecuteNoLog($getnext);
98 $this->genID
= mysqli_insert_id($this->_connectionID
);
107 // ADODB _connect function wrapper to work with OpenEMR
108 // Needed to do this to add support for mysql ssl.
109 // (so only have added the mysqli_ssl_set stuff)
110 // returns true or false
111 // To add: parameter int $port,
112 // parameter string $socket
117 $argDatabasename = null,
120 if (!extension_loaded("mysqli")) {
123 $this->_connectionID
= @mysqli_init
();
125 if (is_null($this->_connectionID
)) {
126 // mysqli_init only fails if insufficient memory
128 ADOConnection
::outp("mysqli_init() failed : " . $this->ErrorMsg());
133 I suggest a simple fix which would enable adodb and mysqli driver to
134 read connection options from the standard mysql configuration file
135 /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
137 foreach ($this->optionFlags
as $arr) {
138 mysqli_options($this->_connectionID
, $arr[0], $arr[1]);
141 //http ://php.net/manual/en/mysqli.persistconns.php
142 if ($persist && PHP_VERSION
> 5.2 && strncmp($argHostname, 'p:', 2) != 0) {
143 $argHostname = 'p:'.$argHostname;
146 //Below was added by OpenEMR to support mysql ssl
147 // Note there is really weird behavior where the paths to certificates do not work if within a variable.
148 // (super odd which is why have 2 different mysqli_ssl_set commands as a work around)
149 if (defined('MYSQLI_CLIENT_SSL') && $this->clientFlags
== MYSQLI_CLIENT_SSL
) {
150 if (file_exists($GLOBALS['OE_SITE_DIR'] . "/documents/certificates/mysql-key") &&
151 file_exists($GLOBALS['OE_SITE_DIR'] . "/documents/certificates/mysql-cert")) {
152 // with client side certificate/key
154 $this->_connectionID
,
155 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-key",
156 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-cert",
157 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-ca",
162 // without client side certificate/key
164 $this->_connectionID
,
167 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-ca",
174 #if (!empty($this->port)) $argHostname .= ":".$this->port;
175 $ok = mysqli_real_connect(
176 $this->_connectionID
,
181 # PHP7 compat: port must be int. Use default port if cast yields zero
182 (int)$this->port
!= 0 ?
(int)$this->port
: 3306,
188 if ($argDatabasename) {
189 return $this->SelectDB($argDatabasename);
194 ADOConnection
::outp("Could't connect : " . $this->ErrorMsg());
196 $this->_connectionID
= null;