mysql.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,557 行 · 第 1/4 页
PHP
1,557 行
* * notnull * Boolean flag that indicates whether this field is * constrained to not be set to NULL. * @return string DBMS specific SQL code portion that should be used to * declare the specified field. * @access public */ function getDecimalDeclaration($name, $field) { return("$name BIGINT". (isset($field['default']) ? ' DEFAULT '.$this->getDecimalValue($field['default']) : ''). (isset($field['notnull']) ? ' NOT NULL' : '') ); } // }}} // {{{ getClobValue() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() * @param $parameter * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ function getClobValue($prepared_query, $parameter, $clob) { $value = "'"; while(!$this->endOfLob($clob)) { if (MDB::isError($result = $this->readLob($clob, $data, $this->options['lob_buffer_length']))) { return($result); } $value .= $this->_quote($data); } $value .= "'"; return($value); } // }}} // {{{ freeClobValue() /** * free a character large object * * @param resource $prepared_query query handle from prepare() * @param string $clob * @return MDB_OK * @access public */ function freeClobValue($prepared_query, $clob) { unset($this->lobs[$clob]); return(MDB_OK); } // }}} // {{{ getBlobValue() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() * @param $parameter * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ function getBlobValue($prepared_query, $parameter, $blob) { $value = "'"; while(!$this->endOfLob($blob)) { if (MDB::isError($result = $this->readLob($blob, $data, $this->options['lob_buffer_length']))) { return($result); } $value .= addslashes($data); } $value .= "'"; return($value); } // }}} // {{{ freeBlobValue() /** * free a binary large object * * @param resource $prepared_query query handle from prepare() * @param string $blob * @return MDB_OK * @access public */ function freeBlobValue($prepared_query, $blob) { unset($this->lobs[$blob]); return(MDB_OK); } // }}} // {{{ getFloatValue() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ function getFloatValue($value) { return(($value === NULL) ? 'NULL' : (float)$value); } // }}} // {{{ getDecimalValue() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ function getDecimalValue($value) { return(($value === NULL) ? 'NULL' : strval(round(doubleval($value)*$this->decimal_factor))); } // }}} // {{{ nextId() /** * returns the next free id of a sequence * * @param string $seq_name name of the sequence * @param boolean $ondemand when true the seqence is * automatic created, if it * not exists * * @return mixed MDB_Error or id * @access public */ function nextId($seq_name, $ondemand = TRUE) { $sequence_name = $this->getSequenceName($seq_name); $this->expectError(MDB_ERROR_NOSUCHTABLE); $result = $this->query("INSERT INTO $sequence_name (" .$this->options['sequence_col_name'].") VALUES (NULL)"); $this->popExpect(); if ($ondemand && MDB::isError($result) && $result->getCode() == MDB_ERROR_NOSUCHTABLE) { // Since we are create the sequence on demand // we know the first id = 1 so initialize the // sequence at 2 $result = $this->createSequence($seq_name, 2); if (MDB::isError($result)) { return($this->raiseError(MDB_ERROR, NULL, NULL, 'Next ID: on demand sequence could not be created')); } else { // First ID of a newly created sequence is 1 return(1); } } $value = intval(@mysql_insert_id($this->connection)); $res = $this->query("DELETE FROM $sequence_name WHERE " .$this->options['sequence_col_name']." < $value"); if (MDB::isError($res)) { $this->warnings[] = 'Next ID: could not delete previous sequence table values'; } return($value); } // }}} // {{{ currId() /** * returns the current id of a sequence * * @param string $seq_name name of the sequence * @return mixed MDB_Error or id * @access public */ function currId($seq_name) { $sequence_name = $this->getSequenceName($seq_name); $result = $this->query("SELECT MAX(".$this->options['sequence_col_name'].") FROM $sequence_name", 'integer'); if (MDB::isError($result)) { return($result); } return($this->fetchOne($result)); } // }}} // {{{ fetchInto() /** * Fetch a row and insert the data into an existing array. * * @param resource $result result identifier * @param int $fetchmode how the array data should be indexed * @param int $rownum the row number to fetch * @return int data array on success, a MDB error on failure * @access public */ function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = NULL) { $result_value = intval($result); if ($rownum == NULL) { ++$this->highest_fetched_row[$result_value]; } else { if (!@mysql_data_seek($result, $rownum)) { return(NULL); } $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; } if ($fetchmode & MDB_FETCHMODE_ASSOC) { $row = @mysql_fetch_assoc($result); if (is_array($row) && $this->options['optimize'] == 'portability') { $row = array_change_key_case($row, CASE_LOWER); } } else { $row = @mysql_fetch_row($result); } if (!$row) { if($this->options['autofree']) { $this->freeResult($result); } return(NULL); } if (isset($this->result_types[$result_value])) { $row = $this->convertResultRow($result, $row); } return($row); } // }}} // {{{ nextResult() /** * Move the internal mysql result pointer to the next available result * Currently not supported * * @param a valid result resource * @return true if a result is available otherwise return false * @access public */ function nextResult($result) { return(FALSE); } // }}} // {{{ tableInfo() /** * returns meta data about the result set * * @param resource $result result identifier * @param mixed $mode depends on implementation * @return array an nested array, or a MDB error * @access public */ function tableInfo($result, $mode = NULL) { $count = 0; $id = 0; $res = array(); /* * depending on $mode, metadata returns the following values: * * - mode is false (default): * $result[]: * [0]['table'] table name * [0]['name'] field name * [0]['type'] field type * [0]['len'] field length * [0]['flags'] field flags * * - mode is MDB_TABLEINFO_ORDER * $result[]: * ['num_fields'] number of metadata records * [0]['table'] table name * [0]['name'] field name * [0]['type'] field type * [0]['len'] field length * [0]['flags'] field flags * ['order'][field name] index of field named "field name" * The last one is used, if you have a field name, but no index. * Test: if (isset($result['meta']['myfield'])) { ... * * - mode is MDB_TABLEINFO_ORDERTABLE * the same as above. but additionally * ['ordertable'][table name][field name] index of field * named 'field name' * * this is, because if you have fields from different * tables with the same field name * they override each * other with MDB_TABLEINFO_ORDER * * you can combine MDB_TABLEINFO_ORDER and * MDB_TABLEINFO_ORDERTABLE with MDB_TABLEINFO_ORDER | * MDB_TABLEINFO_ORDERTABLE * or with MDB_TABLEINFO_FULL */ // if $result is a string, then we want information about a // table without a resultset if (is_string($result)) { if (MDB::isError($connect = $this->connect())) { return $connect; } $id = @mysql_list_fields($this->database_name, $result, $this->connection); if (empty($id)) { return($this->mysqlRaiseError()); } } else { // else we want information about a resultset $id = $result; if (empty($id)) { return($this->mysqlRaiseError()); } } $count = @mysql_num_fields($id); // made this IF due to performance (one if is faster than $count if's) if (empty($mode)) { for ($i = 0, $j = 0; $i<$count; $i++) { $name = @mysql_field_name($id, $i); if ($name != 'dummy_primary_key') { $res[$j]['table'] = @mysql_field_table($id, $i); $res[$j]['name'] = $name; $res[$j]['type'] = @mysql_field_type($id, $i); $res[$j]['len'] = @mysql_field_len($id, $i); $res[$j]['flags'] = @mysql_field_flags($id, $i); $j++; } } } else { // full $res['num_fields'] = $count; for ($i = 0; $i<$count; $i++) { $name = @mysql_field_name($id, $i); if ($name != 'dummy_primary_key') { $res[$j]['table'] = @mysql_field_table($id, $i); $res[$j]['name'] = $name; $res[$j]['type'] = @mysql_field_type($id, $i); $res[$j]['len'] = @mysql_field_len($id, $i); $res[$j]['flags'] = @mysql_field_flags($id, $i); if ($mode & MDB_TABLEINFO_ORDER) { // note sure if this should be $i or $j $res['order'][$res[$j]['name']] = $i; } if ($mode & MDB_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$j]['table']][$res[$j]['name']] = $j; } $j++; } } } // free the result only if we were called on a table if (is_string($result)) { @mysql_free_result($id); } return($res); }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?