Display fix: width in manila for demographics (#1909)
[openemr.git] / library / ADODB_mysqli_log.php
blobb40fab84566283da2700b67deb6e55e6304fa0f1
1 <?php
2 /**
3 * ADODB custom wrapper class to support ssl option in main.
5 * @package OpenEMR
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
15 /**
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) {
26 $outcome = 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();
31 // Last error no
32 $GLOBALS['last_mysql_error_no']=$this->ErrorNo();
33 } else {
34 $outcome = true;
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);
41 return $retval;
44 /**
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) {
76 return false;
79 $getnext = sprintf($this->_genIDSQL, $seqname);
80 $holdtransOK = $this->_transOK; // save the current status
81 $rs = @$this->ExecuteNoLog($getnext);
82 if (!$rs) {
83 if ($holdtransOK) {
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));
90 if (!$cnt) {
91 $this->ExecuteNoLog(sprintf($this->_genSeq2SQL, $seqname, $startID-1));
94 $rs = $this->ExecuteNoLog($getnext);
97 if ($rs) {
98 $this->genID = mysqli_insert_id($this->_connectionID);
99 $rs->Close();
100 } else {
101 $this->genID = 0;
104 return $this->genID;
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
113 function _connect(
114 $argHostname = null,
115 $argUsername = null,
116 $argPassword = null,
117 $argDatabasename = null,
118 $persist = false
120 if (!extension_loaded("mysqli")) {
121 return null;
123 $this->_connectionID = @mysqli_init();
125 if (is_null($this->_connectionID)) {
126 // mysqli_init only fails if insufficient memory
127 if ($this->debug) {
128 ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg());
130 return false;
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
153 mysqli_ssl_set(
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",
158 null,
159 null
161 } else {
162 // without client side certificate/key
163 mysqli_ssl_set(
164 $this->_connectionID,
165 null,
166 null,
167 "${GLOBALS['OE_SITE_DIR']}/documents/certificates/mysql-ca",
168 null,
169 null
174 #if (!empty($this->port)) $argHostname .= ":".$this->port;
175 $ok = mysqli_real_connect(
176 $this->_connectionID,
177 $argHostname,
178 $argUsername,
179 $argPassword,
180 $argDatabasename,
181 # PHP7 compat: port must be int. Use default port if cast yields zero
182 (int)$this->port != 0 ? (int)$this->port : 3306,
183 $this->socket,
184 $this->clientFlags
187 if ($ok) {
188 if ($argDatabasename) {
189 return $this->SelectDB($argDatabasename);
191 return true;
192 } else {
193 if ($this->debug) {
194 ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
196 $this->_connectionID = null;
197 return false;