Properly fixed possible MySQL Errors, will test in prod for 1 day
Had to rewrite all the mysqli->error/errno to mysqli->lastused because of the read/write splitting, shoud be working now Reverted notifications code back to previous version Added the lastused property to mysqlms, so that when calling the error/errno we know what was the lsat connection used, same for insert_id
This commit is contained in:
parent
12cee6e25a
commit
d259610ac5
@ -253,8 +253,9 @@ class Base {
|
|||||||
$this->setErrorMessage(call_user_func_array(array($this, 'getErrorMsg'), func_get_args()));
|
$this->setErrorMessage(call_user_func_array(array($this, 'getErrorMsg'), func_get_args()));
|
||||||
}
|
}
|
||||||
// Default to SQL error for debug and cron errors
|
// Default to SQL error for debug and cron errors
|
||||||
$this->debug->append($this->getErrorMsg('E0019', $this->mysqli->error));
|
$this->debug->append($this->getErrorMsg('E0019', $this->mysqli->lastused->errno));
|
||||||
$this->setCronMessage($this->getErrorMsg('E0019', $this->mysqli->error));
|
$this->setCronMessage($this->getErrorMsg('E0019', $this->mysqli->lastused->errno));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class mysqlims extends mysqli
|
|||||||
private $mysqliW;
|
private $mysqliW;
|
||||||
private $mysqliR = null;
|
private $mysqliR = null;
|
||||||
private $slave = false;
|
private $slave = false;
|
||||||
|
public $lastused = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pass main and slave connection arrays to the constructor, and strict as true/false
|
* 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)
|
public function prepare($query)
|
||||||
{
|
{
|
||||||
if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->slave !== false) {
|
if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->slave !== false) {
|
||||||
|
$this->lastused = $this->mysqliR;
|
||||||
return $this->mysqliR->prepare($query);
|
return $this->mysqliR->prepare($query);
|
||||||
} else {
|
} else {
|
||||||
|
$this->lastused = $this->mysqliW;
|
||||||
return $this->mysqliW->prepare($query);
|
return $this->mysqliW->prepare($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,8 +81,10 @@ class mysqlims extends mysqli
|
|||||||
public function query($query, $resultmode = MYSQLI_STORE_RESULT)
|
public function query($query, $resultmode = MYSQLI_STORE_RESULT)
|
||||||
{
|
{
|
||||||
if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->slave !== false) {/* Use readonly server */
|
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);
|
return $this->mysqliR->query($query, $resultmode);
|
||||||
} else {
|
} else {
|
||||||
|
$this->lastused = $this->mysqliW;
|
||||||
return $this->mysqliW->query($query, $resultmode);
|
return $this->mysqliW->query($query, $resultmode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,17 +22,11 @@ class Notification extends Mail {
|
|||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
$data = json_encode($aData);
|
$data = json_encode($aData);
|
||||||
$stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE data = ? AND active = 1 LIMIT 1");
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $stmt->errno )
|
return $this->sqlError('E0041');
|
||||||
{
|
|
||||||
return $this->sqlError();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class Template extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->setErrorMessage('Failed to get active templates');
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ class Template extends Base {
|
|||||||
return $result->fetch_assoc();
|
return $result->fetch_assoc();
|
||||||
|
|
||||||
$this->setErrorMessage('Failed to get the template');
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ class Template extends Base {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
$this->setErrorMessage('Database error');
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -575,7 +575,7 @@ class User extends Base {
|
|||||||
}
|
}
|
||||||
// Catchall
|
// Catchall
|
||||||
$this->setErrorMessage('Failed to update your account');
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,7 +832,7 @@ class User extends Base {
|
|||||||
$signup_time = time();
|
$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()) {
|
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 (!is_null($coinaddress)) $this->coin_address->add($new_account_id, $coinaddress);
|
||||||
if (! $this->setting->getValue('accounts_confirm_email_disabled') && $is_admin != 1) {
|
if (! $this->setting->getValue('accounts_confirm_email_disabled') && $is_admin != 1) {
|
||||||
if ($token = $this->token->createToken('confirm_email', $stmt->insert_id)) {
|
if ($token = $this->token->createToken('confirm_email', $stmt->insert_id)) {
|
||||||
@ -855,8 +855,8 @@ class User extends Base {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->setErrorMessage( 'Unable to register' );
|
$this->setErrorMessage( 'Unable to register' );
|
||||||
$this->debug->append('Failed to insert user into DB: ' . $this->mysqli->error);
|
$this->debug->append('Failed to insert user into DB: ' . $this->mysqli->lastused->error);
|
||||||
echo $this->mysqli->error;
|
echo $this->mysqli->lastused->error;
|
||||||
if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username or email already registered' );
|
if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username or email already registered' );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -895,7 +895,7 @@ class User extends Base {
|
|||||||
} else {
|
} else {
|
||||||
$this->setErrorMessage('Invalid token: ' . $this->token->getError());
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user