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 MySQLiResultSet.php.
MySQLiResultSet::close | ( | ) |
Implements ResultSet.
Definition at line 99 of file MySQLiResultSet.php.
MySQLiResultSet::getRecordCount | ( | ) |
Implements ResultSet.
Definition at line 85 of file MySQLiResultSet.php.
00086 { 00087 $rows = @mysqli_num_rows($this->result); 00088 00089 if ($rows === null) { 00090 throw new SQLException("Error fetching num rows", mysqli_error($this->conn->getResource())); 00091 } 00092 00093 return (int) $rows; 00094 }
MySQLiResultSet::getString | ( | $ | column | ) |
Get string version of column.
No rtrim() necessary for MySQL, as this happens natively.
Reimplemented from ResultSetCommon.
Definition at line 110 of file MySQLiResultSet.php.
00111 { 00112 $idx = (is_int($column) ? $column - 1 : $column); 00113 00114 if (!array_key_exists($idx, $this->fields)) { 00115 throw new SQLException("Invalid resultset column: " . $column); 00116 } 00117 00118 if ($this->fields[$idx] === null) { 00119 return null; 00120 } 00121 00122 return (string) $this->fields[$idx]; 00123 }
MySQLiResultSet::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 131 of file MySQLiResultSet.php.
00131 :i:s') 00132 { 00133 if (is_int($column)) { 00134 // because Java convention is to start at 1 00135 $column--; 00136 } 00137 00138 if (!array_key_exists($column, $this->fields)) { 00139 throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); 00140 } 00141 00142 if ($this->fields[$column] === null) { 00143 return null; 00144 } 00145 00146 $ts = strtotime($this->fields[$column]); 00147 00148 if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE 00149 // otherwise it's an ugly MySQL timestamp! 00150 // YYYYMMDDHHMMSS 00151 if (preg_match('/([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/', $this->fields[$column], $matches)) { 00152 // YYYY MM DD HH MM SS 00153 // $1 $2 $3 $4 $5 $6 00154 $ts = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 00155 } 00156 } 00157 00158 if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE 00159 // if it's still -1, then there's nothing to be done; use a different method. 00160 throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$column]); 00161 } 00162 00163 if ($format === null) { 00164 return $ts; 00165 } 00166 00167 if (strpos($format, '%') !== false) { 00168 return strftime($format, $ts); 00169 } else { 00170 return date($format, $ts); 00171 } 00172 }
MySQLiResultSet::next | ( | ) |
Implements ResultSet.
Definition at line 56 of file MySQLiResultSet.php.
References ResultSetCommon::afterLast(), and ResultSet::FETCHMODE_ASSOC.
00057 { 00058 $this->fields = mysqli_fetch_array($this->result, $this->fetchmode); 00059 $resource = $this->conn->getResource(); 00060 00061 if (!$this->fields) { 00062 $errno = mysqli_errno($resource); 00063 00064 if (!$errno) { 00065 // We've advanced beyond end of recordset. 00066 $this->afterLast(); 00067 return false; 00068 } else { 00069 throw new SQLException("Error fetching result", mysqli_error($resource)); 00070 } 00071 } 00072 00073 if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) { 00074 $this->fields = array_change_key_case($this->fields, CASE_LOWER); 00075 } 00076 00077 // Advance cursor position 00078 $this->cursorPos++; 00079 return true; 00080 }
MySQLiResultSet::seek | ( | $ | rownum | ) |
Implements ResultSet.
Definition at line 40 of file MySQLiResultSet.php.
00041 { 00042 // MySQL rows start w/ 0, but this works, because we are 00043 // looking to move the position _before_ the next desired position 00044 if (!@mysqli_data_seek($this->result, $rownum)) { 00045 return false; 00046 } 00047 00048 $this->cursorPos = $rownum; 00049 00050 return true; 00051 }