Public Member Functions | |
seek ($rownum) | |
next () | |
getRecordCount () | |
close () | |
getString ($column) | |
Get string version of column. | |
getTimestamp ($column, $format='Y-m-d H:i:s') | |
Returns a unix epoch timestamp based on either a TIMESTAMP or DATETIME field. |
Definition at line 36 of file MySQLResultSet.php.
MySQLResultSet::close | ( | ) |
MySQLResultSet::getRecordCount | ( | ) |
Implements ResultSet.
Definition at line 82 of file MySQLResultSet.php.
00083 { 00084 $rows = @mysql_num_rows($this->result); 00085 if ($rows === null) { 00086 throw new SQLException("Error fetching num rows", mysql_error($this->conn->getResource())); 00087 } 00088 return (int) $rows; 00089 }
MySQLResultSet::getString | ( | $ | column | ) |
Get string version of column.
No rtrim() necessary for MySQL, as this happens natively.
Reimplemented from ResultSetCommon.
Definition at line 105 of file MySQLResultSet.php.
00106 { 00107 $idx = (is_int($column) ? $column - 1 : $column); 00108 if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } 00109 if ($this->fields[$idx] === null) { return null; } 00110 return (string) $this->fields[$idx]; 00111 }
MySQLResultSet::getTimestamp | ( | $ | column, | |
$ | format = 'Y-m-d H:i:s' | |||
) |
Returns a unix epoch timestamp based on either a TIMESTAMP or DATETIME field.
mixed | $column Column name (string) or index (int) starting with 1. |
SQLException | - If the column specified is not a valid key in current field array. |
Reimplemented from ResultSetCommon.
Definition at line 119 of file MySQLResultSet.php.
00119 :i:s') 00120 { 00121 if (is_int($column)) { $column--; } // because Java convention is to start at 1 00122 if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); } 00123 if ($this->fields[$column] === null) { return null; } 00124 00125 $ts = strtotime($this->fields[$column]); 00126 if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE 00127 // otherwise it's an ugly MySQL timestamp! 00128 // YYYYMMDDHHMMSS 00129 if (preg_match('/([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/', $this->fields[$column], $matches)) { 00130 // YYYY MM DD HH MM SS 00131 // $1 $2 $3 $4 $5 $6 00132 $ts = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 00133 } 00134 } 00135 if ($ts === -1 || $ts === false) { // if it's still -1, then there's nothing to be done; use a different method. 00136 throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$column]); 00137 } 00138 if ($format === null) { 00139 return $ts; 00140 } 00141 if (strpos($format, '%') !== false) { 00142 return strftime($format, $ts); 00143 } else { 00144 return date($format, $ts); 00145 } 00146 }
MySQLResultSet::next | ( | ) |
Implements ResultSet.
Definition at line 55 of file MySQLResultSet.php.
References ResultSetCommon::afterLast(), and ResultSet::FETCHMODE_ASSOC.
00056 { 00057 $this->fields = mysql_fetch_array($this->result, $this->fetchmode); 00058 00059 if (!$this->fields) { 00060 $errno = mysql_errno($this->conn->getResource()); 00061 if (!$errno) { 00062 // We've advanced beyond end of recordset. 00063 $this->afterLast(); 00064 return false; 00065 } else { 00066 throw new SQLException("Error fetching result", mysql_error($this->conn->getResource())); 00067 } 00068 } 00069 00070 if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) { 00071 $this->fields = array_change_key_case($this->fields, CASE_LOWER); 00072 } 00073 00074 // Advance cursor position 00075 $this->cursorPos++; 00076 return true; 00077 }
MySQLResultSet::seek | ( | $ | rownum | ) |
Implements ResultSet.
Definition at line 41 of file MySQLResultSet.php.
00042 { 00043 // MySQL rows start w/ 0, but this works, because we are 00044 // looking to move the position _before_ the next desired position 00045 if (!@mysql_data_seek($this->result, $rownum)) { 00046 return false; 00047 } 00048 $this->cursorPos = $rownum; 00049 return true; 00050 }