/** * This function will connect to the database, execute a query and will return the result handle. * * @param $sql The SQL statement to execute. * * @returns Handle to the result of the query. * * @internal */ function &_connectAndExec($sql) { // Add the table prefix $sql = str_replace(' #_', ' ' . YDConfig::get('YD_DB_TABLEPREFIX', ''), $sql); $sql = str_replace(' `#_', ' `' . YDConfig::get('YD_DB_TABLEPREFIX', ''), $sql); // Connect $result = $this->connect(); // Handle errors if (!$result && is_null($this->_conn) && $this->_failOnError === true) { trigger_error(mysql_error(), YD_ERROR); } if (!$result && !is_null($this->_conn) && $this->_failOnError === true) { trigger_error(mysql_error($this->_conn), YD_ERROR); } // Record the start time $timer = new YDTimer(); // Execute the query $result = @mysql_query($sql, $this->_conn); // Handle errors if ($result === false && $this->_failOnError === true) { YDDebugUtil::error('[' . mysql_errno($this->_conn) . '] ' . mysql_error($this->_conn), $sql); } // Log the statement $this->_logSql($sql, $timer->getElapsed()); // Return the result return $result; }
/** * This function will connect to the database, execute a query and will return the result handle. * * @param $sql The SQL statement to execute. * * @returns Handle to the result of the query. * * @internal */ function &_connectAndExec($sql) { // Add the table prefix $sql = str_replace(' #_', ' ' . YDConfig::get('YD_DB_TABLEPREFIX', ''), $sql); $sql = str_replace(' `#_', ' `' . YDConfig::get('YD_DB_TABLEPREFIX', ''), $sql); // Update the language placeholders $languageIndex = YDConfig::get('YD_DB_LANGUAGE_INDEX', null); if (!is_null($languageIndex)) { $sql = str_replace('_@', '_' . $languageIndex, $sql); } // Connect $result = $this->connect(); // Handle errors if (!$result && is_null($this->_conn) && $this->_failOnError === true) { trigger_error(mysql_error(), YD_ERROR); } if (!$result && !is_null($this->_conn) && $this->_failOnError === true) { trigger_error(mysql_error($this->_conn), YD_ERROR); } // Record the start time $timer = new YDTimer(); // Execute the query $result = @mysql_query($sql, $this->_conn); // Log the statement $this->_logSql($sql, $timer->getElapsed()); // Handle errors if ($result === false) { $callback = YDConfig::get('YD_DB_ERROR_CALLBACK'); // check if we should display the error or execute some callback if (is_string($callback) || is_array($callback)) { return call_user_func($callback, $sql, mysql_error($this->_conn), mysql_errno($this->_conn)); } elseif ($callback === false && $this->_failOnError === true) { YDDebugUtil::error('[' . mysql_errno($this->_conn) . '] ' . mysql_error($this->_conn), $sql); } } // Return the result return $result; }