/** * connect to the database * * @param bool $selectdb select the database now? * @return bool successful? */ public function connect($selectdb = true) { if (!extension_loaded('mysqli')) { trigger_error('notrace:mysqli extension not loaded', E_USER_ERROR); return false; } $this->allowWebChanges = $_SERVER['REQUEST_METHOD'] !== 'GET'; if ($selectdb) { $dbname = constant('XOOPS_DB_NAME'); } else { $dbname = ''; } if (XOOPS_DB_PCONNECT == 1) { $this->conn = new mysqli('p:' . XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname); } else { $this->conn = new mysqli(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname); } // errno is 0 if connect was successful if (0 !== $this->conn->connect_errno) { return false; } if (defined('XOOPS_DB_CHARSET') && '' !== XOOPS_DB_CHARSET) { // $this->queryF("SET NAMES '" . XOOPS_DB_CHARSET . "'"); $this->conn->set_charset(XOOPS_DB_CHARSET); } $this->queryF('SET SQL_BIG_SELECTS = 1'); return true; }
/** * @param XoopsDatabase $db * @param $table * @param $field * @param string $condition * * @return bool */ function getDbValue(XoopsDatabase $db, $table, $field, $condition = '') { $table = $db->prefix($table); $sql = "SELECT `{$field}` FROM `{$table}`"; if ($condition) { $sql .= " WHERE {$condition}"; } $result = $db->query($sql); if ($result) { $row = $db->fetchRow($result); if ($row) { return $row[0]; } } return false; }
/** * Enter description here... * * @param string $sql * @param int $limit * @param int $start * @return boolean */ function &_query($sql, $limit = 0, $start = 0) { if (!($result =& $this->_db->query($sql, $limit, $start))) { $this->_error = $this->_db->error(); $result = false; } return $result; }
/** * Assign a value to 1 field for tickets matching a set of conditions * * @param string $fieldname * @param string $fieldvalue * @param object $criteria {@link CriteriaElement} * * @return bool FALSE if update failed * @access public */ public function updateAll($fieldname, $fieldvalue, $criteria = null) { $set_clause = is_numeric($fieldvalue) ? $fieldname . ' = ' . $fieldvalue : $fieldname . ' = ' . $this->_db->quoteString($fieldvalue); $sql = 'UPDATE ' . $this->_db->prefix($this->_dbtable) . ' SET ' . $set_clause; if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' ' . $criteria->renderWhere(); } if (!($result = $this->_db->query($sql))) { return false; } return true; }
/** * This method allows to copy fields from one table to another * * @param array $fieldsMap Map of the fields * ex: array('oldfieldname' => 'newfieldname'); * @param string $oTableName Old Table * @param string $nTableName New Table * @param bool $dropTable Drop old Table * * @return this does not return anything */ public function copyFields($fieldsMap, $oTableName, $nTableName, $dropTable = false) { $sql = "SHOW COLUMNS FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); if (($rows = $this->db->getRowsNum($result)) == count($fieldsMap)) { $sql = "SELECT * FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); while ($myrow = $this->db->fetchArray($result)) { ksort($fieldsMap); ksort($myrow); $sql = "INSERT INTO `" . $this->db->prefix($nTableName) . "` " . "(`" . implode("`,`", $fieldsMap) . "`)" . " VALUES ('" . implode("','", $myrow) . "')"; $this->db->queryF($sql); } if ($dropTable) { $sql = "DROP TABLE " . $this->db->prefix($oTableName); $this->db->queryF($sql); } } }
/** * fetch the next row of a result set * * @param resource &$result as returned by query * * @return bool true if no errors and table is loaded, false if * error presented. Error message in $this->lastError; */ private function fetch(&$result) { return $this->db->fetchArray($result); }
/** * fetch the next row of a result set * * @param resource $result as returned by query * * @return mixed false on error */ protected function fetch($result) { return $this->db->fetchArray($result); }