| | |
| | | } |
| | | */ |
| | | if(mysqli_connect_error()) { |
| | | $this->errorNumber = mysqli_connect_errno(); |
| | | $this->errorMessage = mysqli_connect_error(); |
| | | $this->errorNumber = $this->connect_errno; |
| | | $this->errorMessage = $this->connect_error; |
| | | } else { |
| | | $this->errorNumber = mysqli_errno($this); |
| | | $this->errorMessage = mysqli_error($this); |
| | |
| | | } |
| | | |
| | | public function query($queryString) { |
| | | global $app; |
| | | |
| | | if($this->isConnected == false) return false; |
| | | $try = 0; |
| | | do { |
| | |
| | | $ok = $this->ping(); |
| | | if(!$ok) { |
| | | if(!$this->real_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName)) { |
| | | $this->updateError('DB::query -> reconnect'); |
| | | if($this->errorNumber == '111') { |
| | | // server is not available |
| | | if($try > 9) { |
| | | if(isset($app) && isset($app->forceErrorExit)) { |
| | | $app->forceErrorExit('Database connection failure!'); |
| | | } |
| | | // if we reach this, the app object is missing or has no exit method, so we continue as normal |
| | | } |
| | | sleep(30); // additional seconds, please! |
| | | } |
| | | |
| | | if($try > 9) { |
| | | $this->updateError('DB::query -> reconnect'); |
| | | return false; |
| | | } else { |
| | | sleep(($try > 7 ? 5 : 1)); |
| | |
| | | } |
| | | } while($ok == false); |
| | | $this->queryId = parent::query($queryString); |
| | | $this->updateError('DB::query('.$queryString.') -> mysqli_query'); |
| | | if(!$this->queryId) $this->updateError('DB::query('.$queryString.') -> mysqli_query'); |
| | | if(!$this->queryId) { |
| | | return false; |
| | | } |
| | |
| | | // returns the next record in an array |
| | | public function nextRecord() { |
| | | $this->record = $this->queryId->fetch_assoc(); |
| | | $this->updateError('DB::nextRecord()-> mysql_fetch_array'); |
| | | if(!$this->record || !is_array($this->record)) |
| | | { |
| | | $this->updateError('DB::nextRecord()-> mysql_fetch_array'); |
| | | return false; |
| | | } |
| | | $this->currentRow++; |