/** * Execute SQL query * * @param string $sql_statement * @return MysqlQuery */ public function exec($sql_statement) { $query_str = ''; if (empty($sql_statement)) { if (!empty($this->sql_statement)) { $query_str = $this->sql_statement; } else { throw new EmptyArgumentException(); } } else { $query_str = $sql_statement; } if ($this->log) { $this->logger->log(static::LOGGER_NAME, $sql_statement); } if (($this->result = mysql_query($query_str, $this->db_link)) != false) { $this->last_fetch_type = ''; $this->last_field_position = 0; $this->last_record_position = 0; return $this; } else { $errorCode = $this->errorCode(); $errorMessage = $this->errorMessage(); if ($errorCode == 1146) { preg_match("/Table \\'.*?\\.(.+?)\\' doesn\\'t exist/", $errorMessage, $matches); if (isset($matches[1])) { $nonExistantTableName = $matches[1]; if (!in_array($nonExistantTableName, $this->nonExitentTables)) { $sqlFiles = Tbl::getPluginSQLFilePathsByTableName($nonExistantTableName); if ($sqlFiles !== false) { $db = Reg::get(ConfigManager::getConfig("Db", "Db")->Objects->Db); $db->startTransaction(); foreach ($sqlFiles as $sqlFilePath) { self::executeSQLFile($sqlFilePath); } if ($db->commit()) { array_push($this->nonExitentTables, $nonExistantTableName); return $this->exec($sql_statement); } else { $db->rollBack(); } } } } } throw new MySqlException("MySQL Error: {$errorCode}: {$errorMessage} in query `{$sql_statement}`", $errorCode); } }