function query($sql, $conn) { try { $result = db2_exec($conn, $sql); $count = 0; while ($row = db2_fetch_object($result)) { echo $row->NAME1 . ", " . $row->NAME2 . " " . $row->STREET . ", " . $row->CITY . ", " . $row->STATE . ", " . $row->ZIP . ", " . $row->COUNTY . ", " . $row->LONG . ", " . $row->LAT . "<br>"; $count++; } //print_r($result); if ($result) { echo "Query Successful<br>" . $count . " total entries<br>"; } } catch (Exception $e) { echo "Query Failed<br>"; echo "Exception: " . $e->getMessage() . "<br>"; echo db2_conn_error() . "<br>"; echo db2_conn_errormsg() . "<br>"; } }
/** * Fetches a row from the result set. * * @param int $style OPTIONAL Fetch mode for this fetch operation. * @param int $cursor OPTIONAL Absolute, relative, or other. * @param int $offset OPTIONAL Number for absolute or relative cursors. * @return mixed Array, object, or scalar depending on fetch mode. * @throws Zend_Db_Statement_Db2_Exception */ public function fetch($style = null, $cursor = null, $offset = null) { if (!$this->_stmt) { return false; } if ($style === null) { $style = $this->_fetchMode; } switch ($style) { case Zend_Db::FETCH_NUM: $row = db2_fetch_array($this->_stmt); break; case Zend_Db::FETCH_ASSOC: $row = db2_fetch_assoc($this->_stmt); break; case Zend_Db::FETCH_BOTH: $row = db2_fetch_both($this->_stmt); break; case Zend_Db::FETCH_OBJ: $row = db2_fetch_object($this->_stmt); break; case Zend_Db::FETCH_BOUND: $row = db2_fetch_both($this->_stmt); if ($row !== false) { return $this->_fetchBound($row); } break; default: /** * @see Zend_Db_Statement_Db2_Exception */ require_once PHP_LIBRARY_PATH . 'Zend/Db/Statement/Db2/Exception.php'; throw new Zend_Db_Statement_Db2_Exception("Invalid fetch mode '{$style}' specified"); break; } return $row; }
/** * Fetches a row from the result set. * * @param int $style OPTIONAL Fetch mode for this fetch operation. * @param int $cursor OPTIONAL Absolute, relative, or other. * @param int $offset OPTIONAL Number for absolute or relative cursors. * @return mixed Array, object, or scalar depending on fetch mode. * @throws \Zend\Db\Statement\Db2Exception */ public function fetch($style = null, $cursor = null, $offset = null) { if (!$this->_stmt) { return false; } if ($style === null) { $style = $this->_fetchMode; } switch ($style) { case Db\Db::FETCH_NUM: $row = db2_fetch_array($this->_stmt); break; case Db\Db::FETCH_ASSOC: $row = db2_fetch_assoc($this->_stmt); break; case Db\Db::FETCH_BOTH: $row = db2_fetch_both($this->_stmt); break; case Db\Db::FETCH_OBJ: $row = db2_fetch_object($this->_stmt); break; case Db\Db::FETCH_BOUND: $row = db2_fetch_both($this->_stmt); if ($row !== false) { return $this->_fetchBound($row); } break; default: throw new Db2Exception("Invalid fetch mode '{$style}' specified"); break; } return $row; }
/** * {@inheritdoc} */ public function fetch($fetchMode = null) { $fetchMode = $fetchMode ?: $this->_defaultFetchMode; switch ($fetchMode) { case \PDO::FETCH_BOTH: return db2_fetch_both($this->_stmt); case \PDO::FETCH_ASSOC: return db2_fetch_assoc($this->_stmt); case \PDO::FETCH_CLASS: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; if (func_num_args() >= 2) { $args = func_get_args(); $className = $args[1]; $ctorArgs = isset($args[2]) ? $args[2] : array(); } $result = db2_fetch_object($this->_stmt); if ($result instanceof \stdClass) { $result = $this->castObject($result, $className, $ctorArgs); } return $result; case \PDO::FETCH_NUM: return db2_fetch_array($this->_stmt); case \PDO::FETCH_OBJ: return db2_fetch_object($this->_stmt); default: throw new DB2Exception("Given Fetch-Style " . $fetchMode . " is not supported."); } }
/** * Fetch the next row from the given result object, in object form. * Fields can be retrieved with $row->fieldname, with fields acting like * member variables. * * @param $res array|ResultWrapper SQL result object as returned from Database::query(), etc. * @return DB2 row object * @throws DBUnexpectedError Thrown if the database returns an error */ public function fetchObject($res) { if ($res instanceof ResultWrapper) { $res = $res->result; } wfSuppressWarnings(); $row = db2_fetch_object($res); wfRestoreWarnings(); if ($this->lastErrno()) { throw new DBUnexpectedError($this, 'Error in fetchObject(): ' . htmlspecialchars($this->lastError())); } return $row; }
<?php require 'php/connection.php'; $orderID = ""; $orderTime = "N/A"; $shippingType = "Unknown"; $shippingPrice = "Unknown"; $tax = "Unknown"; $products = "No products bought"; if (isset($_GET['orderID'])) { $query = "SELECT * FROM orderedItems join orderInfo on orderedItems.orderID = orderInfo.orderID WHERE orderID = " + orderID + ";"; $results = db2_exec($_SESSION['connection'], $query); //only one entry while ($row = db2_fetch_object($results)) { $orderID = $row->orderID; $orderTime = $row->orderTime; $shippingType = $row->shippingType; $shippingPrice = $row->shippingPrice; $tax = $row->tax; $productID = $row->productID; } }
/** * This function fetches a result row as an object. * * @param mixed $result * @return mixed * @access public * @author Thorsten Rinne <*****@*****.**> * @author Helmut Tessarek <*****@*****.**> * @since 2005-04-16 */ function fetchObject($result) { $_result = db2_fetch_object($result); if (is_object($_result)) { return (object) array_change_key_case(get_object_vars($_result), CASE_LOWER); } else { return false; } }
public static function fetch_object($psql, $fetchall, $conn = null) { if ($psql) { if (!$fetchall) { return db2_fetch_object($psql); } else { $ret = array(); while ($obj = db2_fetch_object($psql)) { $ret[] = $obj; } return $ret; } } return false; }
/** * Fetch the next row from the given result object, in object form. * Fields can be retrieved with $row->fieldname, with fields acting like * member variables. * * @param $res SQL result object as returned from Database::query(), etc. * @return DB2 row object * @throws DBUnexpectedError Thrown if the database returns an error */ public function fetchObject($res) { if ($res instanceof ResultWrapper) { $res = $res->result; } @($row = db2_fetch_object($res)); if ($this->lastErrno()) { throw new DBUnexpectedError($this, 'Error in fetchObject(): ' . htmlspecialchars($this->lastError())); } // Make field names lowercase for compatibility with MySQL if ($row) { $row2 = new BlankObject(); foreach ($row as $key => $value) { $keyu = strtolower($key); $row2->{$keyu} = $value; } $row = $row2; } return $row; }