diff --git a/include/classes/base.class.php b/include/classes/base.class.php index c29534b2..30d0753c 100644 --- a/include/classes/base.class.php +++ b/include/classes/base.class.php @@ -253,8 +253,9 @@ class Base { $this->setErrorMessage(call_user_func_array(array($this, 'getErrorMsg'), func_get_args())); } // Default to SQL error for debug and cron errors - $this->debug->append($this->getErrorMsg('E0019', $this->mysqli->error)); - $this->setCronMessage($this->getErrorMsg('E0019', $this->mysqli->error)); + $this->debug->append($this->getErrorMsg('E0019', $this->mysqli->lastused->errno)); + $this->setCronMessage($this->getErrorMsg('E0019', $this->mysqli->lastused->errno)); + return false; } diff --git a/include/classes/mysqlims.class.php b/include/classes/mysqlims.class.php index 9a1927f7..98ec503e 100644 --- a/include/classes/mysqlims.class.php +++ b/include/classes/mysqlims.class.php @@ -7,7 +7,8 @@ class mysqlims extends mysqli private $mysqliW; private $mysqliR = null; private $slave = false; - + public $lastused = null; + /* * Pass main and slave connection arrays to the constructor, and strict as true/false * @@ -61,8 +62,10 @@ class mysqlims extends mysqli public function prepare($query) { if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->slave !== false) { + $this->lastused = $this->mysqliR; return $this->mysqliR->prepare($query); } else { + $this->lastused = $this->mysqliW; return $this->mysqliW->prepare($query); } } @@ -78,8 +81,10 @@ class mysqlims extends mysqli public function query($query, $resultmode = MYSQLI_STORE_RESULT) { if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->slave !== false) {/* Use readonly server */ + $this->lastused = $this->mysqliR; return $this->mysqliR->query($query, $resultmode); } else { + $this->lastused = $this->mysqliW; return $this->mysqliW->query($query, $resultmode); } } diff --git a/include/classes/notification.class.php b/include/classes/notification.class.php index 396072c6..48c64e37 100644 --- a/include/classes/notification.class.php +++ b/include/classes/notification.class.php @@ -22,17 +22,11 @@ class Notification extends Mail { $this->debug->append("STA " . __METHOD__, 4); $data = json_encode($aData); $stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE data = ? AND active = 1 LIMIT 1"); - if ($stmt && $stmt->bind_param('s', $data) && $stmt->execute() && $stmt->store_result() && $stmt->num_rows == 1) - { + if ($stmt && $stmt->bind_param('s', $data) && $stmt->execute() && $stmt->store_result() && $stmt->num_rows == 1) { return true; } - - if( $stmt->errno ) - { - return $this->sqlError(); - } - return false; + return $this->sqlError('E0041'); } /** diff --git a/include/classes/template.class.php b/include/classes/template.class.php index dac32fdd..295243f5 100644 --- a/include/classes/template.class.php +++ b/include/classes/template.class.php @@ -79,7 +79,7 @@ class Template extends Base { } $this->setErrorMessage('Failed to get active templates'); - $this->debug->append('Template::getActiveTemplates failed: ' . $this->mysqli->error); + $this->debug->append('Template::getActiveTemplates failed: ' . $this->mysqli->lastused->error); return false; } @@ -172,7 +172,7 @@ class Template extends Base { return $result->fetch_assoc(); $this->setErrorMessage('Failed to get the template'); - $this->debug->append('Template::getEntry failed: ' . $this->mysqli->error); + $this->debug->append('Template::getEntry failed: ' . $this->mysqli->lastused->error); return false; } @@ -206,7 +206,7 @@ class Template extends Base { return true; $this->setErrorMessage('Database error'); - $this->debug->append('Template::updateEntry failed: ' . $this->mysqli->error); + $this->debug->append('Template::updateEntry failed: ' . $this->mysqli->lastused->error); return false; } } diff --git a/include/classes/user.class.php b/include/classes/user.class.php index 8af175d3..77a5507e 100644 --- a/include/classes/user.class.php +++ b/include/classes/user.class.php @@ -575,7 +575,7 @@ class User extends Base { } // Catchall $this->setErrorMessage('Failed to update your account'); - $this->debug->append('Account update failed: ' . $this->mysqli->error); + $this->debug->append('Account update failed: ' . $this->mysqli->lastused->error); return false; } @@ -832,7 +832,7 @@ class User extends Base { $signup_time = time(); if ($this->checkStmt($stmt) && $stmt->bind_param('sssissi', $username_clean, $password_hash, $email1, $signup_time, $pin_hash, $apikey_hash, $is_locked) && $stmt->execute()) { - $new_account_id = $this->mysqli->insert_id; + $new_account_id = $this->mysqli->lastused->insert_id; if (!is_null($coinaddress)) $this->coin_address->add($new_account_id, $coinaddress); if (! $this->setting->getValue('accounts_confirm_email_disabled') && $is_admin != 1) { if ($token = $this->token->createToken('confirm_email', $stmt->insert_id)) { @@ -855,8 +855,8 @@ class User extends Base { } } else { $this->setErrorMessage( 'Unable to register' ); - $this->debug->append('Failed to insert user into DB: ' . $this->mysqli->error); - echo $this->mysqli->error; + $this->debug->append('Failed to insert user into DB: ' . $this->mysqli->lastused->error); + echo $this->mysqli->lastused->error; if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username or email already registered' ); return false; } @@ -895,7 +895,7 @@ class User extends Base { } else { $this->setErrorMessage('Invalid token: ' . $this->token->getError()); } - $this->debug->append('Failed to update password:' . $this->mysqli->error); + $this->debug->append('Failed to update password:' . $this->mysqli->lastused->error); return false; }