function select() { $conn = $this->connect(); if ($conn == true) { $sql = "SELECT name from helloworld"; $result = db2_exec($conn, $sql); while ($row = db2_fetch_array($result)) { echo $text = $row[0]; } } }
function dbQuery($query, $show_errors = true, $all_results = true, $show_output = true) { if ($show_errors) { error_reporting(E_ALL); } else { error_reporting(E_PARSE); } // Connect to the IBM DB2 database management system $link = db2_pconnect("testdb", "db2inst1", "testpass"); if (!$link) { die(db2_conn_errormsg()); } // Print results in HTML print "<html><body>\n"; // Print SQL query to test sqlmap '--string' command line option //print "<b>SQL query:</b> " . $query . "<br>\n"; // Perform SQL injection affected query $stmt = db2_prepare($link, $query); $result = db2_execute($stmt); if (!$result) { if ($show_errors) { print "<b>SQL error:</b> " . db2_stmt_errormsg($stmt) . "<br>\n"; } exit(1); } if (!$show_output) { exit(1); } print "<b>SQL results:</b>\n"; print "<table border=\"1\">\n"; while ($line = db2_fetch_array($stmt)) { print "<tr>"; foreach ($line as $col_value) { print "<td>" . $col_value . "</td>"; } print "</tr>\n"; if (!$all_results) { break; } } print "</table>\n"; print "</body></html>"; }
/** * Performs a SQL statement in database and returns rows. * * @param unknown $sql * the SQL statement. * @throws Exception * @return multitype: */ public function selectDb($sql) { $rowArr = array(); $connection = $this->connect(); $stmt = db2_prepare($connection, $sql); $result = db2_execute($stmt); if ($result) { // echo "Result Set created.\n"; while ($row = db2_fetch_array($stmt)) { array_push($rowArr, $row); } } else { // echo "Result Set not created.\n"; $message = "\nCould not select from database table. " . db2_stmt_errormsg($stmt); throw new Exception($message); } $this->__destruct(); return $rowArr; }
session_unset(); error_reporting(0); session_start(); include 'connect.php'; if (isset($_POST['userName']) && isset($_POST['password'])) { $usernameEntered = $_POST['userName']; $passwordEntered = $_POST['password']; $conn = db2_connect($database, $dbusername, $dbpassword); $sqlquery = "SELECT password FROM OWNER.USERS WHERE email = '{$usernameEntered}' "; $stmt = db2_prepare($conn, $sqlquery); if ($stmt) { $result = db2_execute($stmt); if (!$result) { db2_stmt_errormsg($stmt); } while ($row = db2_fetch_array($stmt)) { $passwordFromDb = $row[0]; } db2_close($conn); echo $passwordFromDb; if ($passwordEntered == $passwordFromDb) { $_SESSION['username'] = $usernameEntered; header('Location: nav.php'); } else { header('Location: login.php'); } } } else { http_response_code(400); }
/** * Constructor for simpledb Proxy * Use the values from the configuration file provided to create a PDO for the database * Query the database to obtain column metadata and primary key * * @param string $target Target * @param string $immediate_caller_directory Directory * @param string $binding_config Config */ public function __construct($target, $immediate_caller_directory, $binding_config) { SCA::$logger->log('Entering constructor'); try { $this->table = $target; $this->config = SCA_Helper::mergeBindingIniAndConfig($binding_config, $immediate_caller_directory); if (array_key_exists('username', $this->config)) { $username = $this->config['username']; } else { $username = null; } if (array_key_exists('password', $this->config)) { $password = $this->config['password']; } else { $password = null; } if (array_key_exists('namespace', $this->config)) { $this->namespace = $this->config['namespace']; } if (array_key_exists('case', $this->config)) { $this->case = $this->config['case']; } else { $this->case = 'lower'; } if (!array_key_exists('dsn', $this->config)) { throw new SCA_RuntimeException("Data source name should be specified"); } $tableName = $this->table; // Special processing for IBM databases: // IBM table names can contain schema name as prefix // Column metadata returned by pdo_ibm does not specify the primary key // Hence primary key for IBM databases has to be obtained using // db2_primary_key. if (strpos($this->config["dsn"], "ibm:") === 0 || strpos($this->config["dsn"], "IBM:") === 0) { $this->isIBM = true; // Table could be of format schemaName.tableName $schemaName = null; if (($pos = strrpos($tableName, '.')) !== false) { $schemaName = substr($tableName, 0, $pos); $tableName = substr($tableName, $pos + 1); } // DSN for IBM databases can be a database name or a connection string // Both can be passed onto db2_connect. Remove the dsn prefix if specified $database = substr($this->config["dsn"], 4); if (strpos($database, "dsn=") === 0 || strpos($database, "DSN=") === 0) { $database = substr($database, 4); } // Need to make sure the name is in DB2 uppercase style $db2TableName = strtoupper($tableName); $conn = db2_connect($database, $username, $password); $stmt = db2_primary_keys($conn, null, $schemaName, $db2TableName); $keys = db2_fetch_array($stmt); if (count($keys) > 3) { $this->primary_key = $keys[3]; } else { throw new SCA_RuntimeException("Table '{$tableName}' does not appear to have a primary key."); } } $this->table_name = $this->_getName($tableName); if ($username != null) { $this->pdo = new PDO($this->config["dsn"], $username, $password, $this->config); } else { $this->pdo = new PDO($this->config["dsn"]); } $this->pdo_driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME); $stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table); if (!$stmt->execute()) { throw new SCA_RuntimeException(self::_getPDOError($stmt, "select")); } $columns = array(); for ($i = 0; $i < $stmt->columnCount(); $i++) { $meta = $stmt->getColumnMeta($i); $name = $this->_getName($meta["name"]); if (in_array("primary_key", $meta["flags"], true)) { $this->primary_key = $name; } $columns[] = $name; } //$pk = $this->_getName($this->primary_key); SCA::$logger->log("Table {$tableName} PrimaryKey {$this->primary_key}"); /* $metadata = array( 'name' => $this->table_name, 'columns' => $columns, 'PK' => $pk ); */ $this->datafactory = SDO_DAS_DataFactory::getDataFactory(); // Define the model on the data factory (from the database) $this->datafactory->addType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE); $this->datafactory->addType($this->namespace, $this->table_name); foreach ($columns as $name) { $this->datafactory->addPropertyToType($this->namespace, $this->table_name, $name, 'commonj.sdo', 'String'); } $this->datafactory->addPropertyToType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE, $this->table_name, $this->namespace, $this->table_name, array('many' => true)); } catch (Exception $e) { throw new SCA_RuntimeException($e->getMessage()); } SCA::$logger->log("Exiting constructor"); }
/** * Fetch the next row from the given result object, in associative array * form. Fields are retrieved with $row['fieldname']. * * @param $res array|ResultWrapper SQL result object as returned from Database::query(), etc. * @return ResultWrapper row object * @throws DBUnexpectedError Thrown if the database returns an error */ public function fetchRow($res) { if ($res instanceof ResultWrapper) { $res = $res->result; } if (db2_num_rows($res) > 0) { wfSuppressWarnings(); $row = db2_fetch_array($res); wfRestoreWarnings(); if ($this->lastErrno()) { throw new DBUnexpectedError($this, 'Error in fetchRow(): ' . htmlspecialchars($this->lastError())); } return $row; } return false; }
<?php include 'config.php'; if (isset($_POST['username'])) { $conn = db2_connect($dbname, $username, $password); if ($conn) { $userName = $_POST['username']; $userNameQuery = "SELECT COUNT(*) FROM " . $computerName . ".USERS WHERE email = '{$userName}' "; $stmt = db2_prepare($conn, $userNameQuery); if ($stmt) { $result = db2_execute($stmt); if ($result) { $username_result = db2_fetch_array($stmt); if ($username_result[0] == '0') { echo 'Username is available'; } else { echo 'Sorry, the Username ' . $userName . ' already exists!'; } } else { db2_stmt_errormsg($stmt); db2_close($conn); } } } }
/** * Retrieves a single row from the database and returns it as an array. * * <b>Note:</b> We don't use the more useful xxx_fetch_array because not all * databases support this function. * * <b>Note:</b> Use the {@link dbi_error()} function to get error information * if the connection fails. * * @param resource $res The database query resource returned from * the {@link dbi_query()} function. * * @return mixed An array of database columns representing a single row in * the query result or false on an error. */ function dbi_fetch_row($res) { if (strcmp($GLOBALS["db_type"], "mysql") == 0) { return mysql_fetch_array($res); } else { if (strcmp($GLOBALS["db_type"], "mysqli") == 0) { return mysqli_fetch_array($res); } else { if (strcmp($GLOBALS["db_type"], "mssql") == 0) { return mssql_fetch_array($res); } else { if (strcmp($GLOBALS["db_type"], "oracle") == 0) { if (OCIFetchInto($GLOBALS["oracle_statement"], $row, OCI_NUM + OCI_RETURN_NULLS)) { return $row; } return 0; } else { if (strcmp($GLOBALS["db_type"], "postgresql") == 0) { if (@$GLOBALS["postgresql_numrows[\"{$res}\"]"] > @$GLOBALS["postgresql_row[\"{$res}\"]"]) { $r = pg_fetch_array($res, @$GLOBALS["postgresql_row[\"{$res}\"]"]); @$GLOBALS["postgresql_row[\"{$res}\"]"]++; if (!$r) { echo "Unable to fetch row\n"; return ''; } } else { $r = ''; } return $r; } else { if (strcmp($GLOBALS["db_type"], "odbc") == 0) { if (!odbc_fetch_into($res, $ret)) { return false; } return $ret; } else { if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) { return db2_fetch_array($res); } else { if (strcmp($GLOBALS["db_type"], "ibase") == 0) { return ibase_fetch_row($res); } else { dbi_fatal_error("dbi_fetch_row(): db_type not defined."); } } } } } } } } }
/** * Fetch a result row as a numeric array * @param Mixed qHanle The query handle * @return Array */ public function fetch_numarray($qHanle) { return db2_fetch_array($qHanle); }
/** * {@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."); } }
/** * {@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_NUM: return db2_fetch_array($this->_stmt); default: throw new DB2Exception("Given Fetch-Style " . $fetchMode . " is not supported."); } }
/** * fetch * * @see Query::HYDRATE_* constants * @param integer $fetchStyle Controls how the next row will be returned to the caller. * This value must be one of the Query::HYDRATE_* constants, * defaulting to Query::HYDRATE_BOTH * * @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor, * this value determines which row will be returned to the caller. * This value must be one of the Query::HYDRATE_ORI_* constants, defaulting to * Query::HYDRATE_ORI_NEXT. To request a scrollable cursor for your * PDOStatement object, * you must set the PDO::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you * prepare the SQL statement with Doctrine_Adapter_Interface->prepare(). * * @param integer $cursorOffset For a PDOStatement object representing a scrollable cursor for which the * $cursorOrientation parameter is set to Query::HYDRATE_ORI_ABS, this value specifies * the absolute number of the row in the result set that shall be fetched. * * For a PDOStatement object representing a scrollable cursor for * which the $cursorOrientation parameter is set to Query::HYDRATE_ORI_REL, this value * specifies the row to fetch relative to the cursor position before * PDOStatement->fetch() was called. * * @return mixed */ function fetch($fetchStyle = \PDO::FETCH_BOTH) { switch ($fetchStyle) { case \PDO::FETCH_BOTH: return db2_fetch_both($this->_stmt); case \PDO::FETCH_ASSOC: return db2_fetch_assoc($this->_stmt); case \PDO::FETCH_NUM: return db2_fetch_array($this->_stmt); default: throw new DB2Exception("Given Fetch-Style " . $fetchStyle . " is not supported."); } }
/** * 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; }
<?php //Connect to database require_once "connect_db.php"; require_once "algorithm.php"; //Pull trait information from database $songname = $_POST["name"]; $sql = "SELECT * FROM \"USER04893\" . \"Songs\" WHERE \"title\" = LCASE('" . $songname . "')"; $stmt = db2_exec($conn4, $sql); $losongs; $row; //Fetches the list of similar songs if (!$stmt) { echo "SQL Statement Failed" . db2_stmt_errormsg() . ""; return; } else { $row = db2_fetch_array($stmt); $top = getSongs($row); $losongs = $top; } ?> <br> <center><img src="images/logo.png" height="300px" width="300px" /></center> <table> <tr> <td colspan="3">The song you searched for is: <?php echo ucwords($row[0]); ?> by <?php echo ucwords($row[1]); ?>
function dbi_fetch_row($res) { if (strcmp($GLOBALS['db_type'], 'mysql') == 0) { return mysql_fetch_array($res, MYSQL_NUM); } elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { return $res->fetch_array(MYSQLI_NUM); } elseif (strcmp($GLOBALS['db_type'], 'mssql') == 0) { return mssql_fetch_array($res); } elseif (strcmp($GLOBALS['db_type'], 'oracle') == 0) { return OCIFetchInto($GLOBALS['oracle_statement'], $row, OCI_NUM + OCI_RETURN_NULLS) ? $row : 0; } elseif (strcmp($GLOBALS['db_type'], 'postgresql') == 0) { // Note: row became optional in PHP 4.1.0. $r = pg_fetch_array($res, null, PGSQL_NUM); return !$r ? false : $r; } elseif (strcmp($GLOBALS['db_type'], 'odbc') == 0) { return !odbc_fetch_into($res, $ret) ? false : $ret; } elseif (strcmp($GLOBALS['db_type'], 'ibm_db2') == 0) { return db2_fetch_array($res); } elseif (strcmp($GLOBALS['db_type'], 'ibase') == 0) { return ibase_fetch_row($res); } elseif (strcmp($GLOBALS['db_type'], 'sqlite') == 0) { return sqlite_fetch_array($res); } else { dbi_fatal_error('dbi_fetch_row (): ' . translate('db_type not defined.')); } }
<?php header('Content-Type: application/json'); require 'connection.php'; if (isset($_GET['school'])) { $rows = array(); $query = "SELECT * FROM school"; $results = db2_exec($_SESSION['connection'], $query); while ($row = db2_fetch_array($results)) { array_push($rows, $row); } print json_encode($rows); } if (isset($_GET['latitude']) and isset($_GET['longitude']) and isset($_GET['radius'])) { $rows = array(); $query = "SELECT * FROM restaurant WHERE db2gse.st_distance( loc, db2gse.ST_POINT(" . $_GET['longitude'] . "," . $_GET['latitude'] . ",1), 'STATUTE MILE') < " . $_GET['radius']; $results = db2_exec($_SESSION['connection'], $query); while ($row = db2_fetch_array($results)) { array_push($rows, $row); } print json_encode($rows); }
/** * * @apiName RtuInformationGeoJSON * @apiGroup RTU Manager * @apiVersion 0.1.0 * * @api {get} /rtuManager/rtuInformationGeoJSON/ RTU Information GeoJSON * @apiDescription คำอธิบาย : ในส่วนนี้ทำหน้าที่แสดงข้อมูล RTU ในรูปแบบ GeoJSON * * * @apiParam {String} name New name of the user * * @apiSampleRequest /rtuManager/rtuInformationGeoJSON/ * * @apiSuccess {String} msg แสดงข้อความทักทายผู้ใช้งาน * * @apiSuccessExample Example data on success: * { * "msg": "Hello, anusorn" * } * * @apiError UserNotFound The <code>id</code> of the User was not found. * @apiErrorExample {json} Error-Response: * HTTP/1.1 404 Not Found * { * "error": "UserNotFound" * } * */ function rtuInformationGeoJSON($app, $pdo, $db, $conn_db2, $key) { $myBranchCode = ""; /* ************************* */ /* เริ่มกระบวนการ Extract the jwt from the Header or Session */ /* ************************* */ if (!isset($_SESSION['jwt'])) { // $jwt = ""; /*** Extract the jwt from the Bearer ***/ $request = $app->request(); $authHeader = $request->headers('authorization'); list($jwt) = sscanf((string) $authHeader, 'Bearer %s'); $myBranchCode = $app->jwt->information->branchCode; } else { /*** Extract the jwt from Session ***/ $jwt = $_SESSION['jwt']; $token = JWT::decode($jwt, $key, array('HS256')); $myBranchCode = $token->information->branchCode; } /* rtuInformationGeoJSON Partial : Production */ /* ************************* */ /* เริ่มกระบวนการเชื่อมต่อฐานข้อมูล MySQL */ /* ************************* */ $features = array(); if ($myBranchCode != "ALL") { $results = $db->rtu_main_tb->where("branch_code = ? and rtu_status = 1", $myBranchCode)->order("dm_code ASC"); } else { $results = $db->rtu_main_tb->where("rtu_status = 1")->order("dm_code ASC"); } foreach ($results as $result) { $result_rtu_pin_code = $db->rtu_pin_code_tb->where("dm_code = ? and enable = 1", $result["dm_code"])->fetch(); /* *********************************** */ /* เริ่มกระบวนการเชื่อมต่อกับฐานข้อมูล DB2 */ /* *********************************** */ $sql_db2 = "select to_char(log_dt, 'YYYY-MM-DD') as Date, area_code, avg(p) as AveragePressure from core_area, meter_hist \nwhere meter_code in (select meter_code from core_area_meter where core_area_meter.area_code = core_area.area_code and meter_inout='I')\nand log_dt between timestamp('" . date("Y-m-d") . "') and timestamp('" . date("Y-m-d") . " 23:59:00')\nand to_char(log_dt, 'HH24') between '05' and '09'\nand area_axis_code = 'D'\nand to_char(area_code) = '" . substr($result["dma_code"], 4) . "'\ngroup by area_code, to_char(log_dt, 'YYYY-MM-DD')"; $tmpAveragePressure = "-"; if ($conn_db2) { // # code... $stmt = db2_exec($conn_db2, $sql_db2); $row = db2_fetch_array($stmt); $tmpAveragePressure = iconv("TIS-620//IGNORE", "UTF-8//IGNORE", $row[2]); if ($tmpAveragePressure) { $tmpAveragePressure = $tmpAveragePressure; } else { $tmpAveragePressure = "-"; } } else { $tmpAveragePressure = "-"; } $tmpID = $result["id"]; $tmpPoint = new \GeoJson\Geometry\Point([floatval($result_rtu_pin_code["lng"]), floatval($result_rtu_pin_code["lat"])]); $tmpProperties = array("dm" => $result["dm_code"], "dma" => $result["dma_code"], "branch" => $result["branch_code"], "zone" => $result["zone_code"], "ip_address" => $result["ip_address"], "logger_code" => $result["logger_code"], "rtu_pin_code" => $result_rtu_pin_code["rtu_pin_code"], "location" => $result_rtu_pin_code["location"], "remark" => $result["remark"], "pressure_avg_date" => date("Y-m-d"), "pressure_avg" => $tmpAveragePressure); $tmpFeature = new \GeoJson\Feature\Feature($tmpPoint, $tmpProperties, $tmpID, null); $features[] = $tmpFeature; } $featureCollection = new \GeoJson\Feature\FeatureCollection($features); /* ************************* */ /* เริ่มกระบวนการส่งค่ากลับ */ /* ************************* */ $app->response()->header("Content-Type", "application/json"); echo json_encode($featureCollection); }
function getSongs($primSong) { //First step is to retrieve the personality values of the user //Connect to database include "connect_db.php"; if (!$conn4) { echo "Connection failed."; print db2_conn_errormsg() . "<br>"; return; } //Run SQL Command to retrieve full database of songs $sql = "SELECT * FROM \"USER04893\" . \"Songs\" WHERE \"title\" != LCASE('" . $primSong[0] . "')"; $stmt = db2_exec($conn4, $sql); if (!$stmt) { print "SQL Statement Failed <br>"; $msg = db2_st_errormsg(); print db2_stmt_errormsg(); print "Error Messsage:"; print $msg . "<br>"; return; } /*Retrieve a song's personality values from the database Pull as a singular record song | artist | trait 1 | trait 2 | trait 3 | ..... */ //print $primSong[2]; $arrayLength = 7; //Number of elements in the array //Beginning of looping to find most compatible song $top = array(); $greatest = 0; $index = 0; $aSize = 0; while ($song = db2_fetch_array($stmt)) { $difference = 0; for ($j = 2; $j < $arrayLength; $j++) { //Now we compare the user's personality values to the song's personality values, here we want the absolute difference $difference += abs($primSong[$j] - $song[$j]); } //Look into top array and see if it should be recommended if ($aSize >= 5 && $difference < $greatest) { //Continue the search, but with the higher value now $top[$index][0] = $song[0]; $top[$index][1] = $difference; $top[$index][2] = $song[1]; $top[$index][3] = $song[7]; $index = getHighest($top); $greatest = $top[$index][1]; } elseif ($aSize < 5) { $top[$aSize][0] = $song[0]; $top[$aSize][1] = $difference; $top[$aSize][2] = $song[1]; $top[$aSize][3] = $song[7]; if ($difference > $greatest) { $greatest = $difference; $index = $aSize; } $aSize++; } } return $top; }
/** * Fetches the next row from the current result set * Maps the records in the $result property to the map * created in resultSet(). * * 2. Gets the actual values. * * @return unknown */ function fetchResult() { if ($row = db2_fetch_array($this->results)) { $resultRow = array(); $i = 0; foreach ($row as $index => $field) { $table = $this->map[$index][0]; $column = strtolower($this->map[$index][1]); $resultRow[$table][$column] = $row[$index]; $i++; } return $resultRow; } return false; }
public static function fetch_num($psql) { if ($psql) { return db2_fetch_array($psql); } return false; }
function _fetch() { $this->fields = db2_fetch_array($this->_queryID); if ($this->fields) { if ($this->fetchMode & ADODB_FETCH_ASSOC) { $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); } return true; } $this->fields = false; return false; }
} } } } } else { $query = "select * from(Select ROW_NUMBER() OVER() as rn, {$computerName}.items.* FROM {$computerName}.items) where rn between {$offset} and {$variable}"; } $stmt = db2_prepare($connection, $query); $result = db2_execute($stmt); if ($stmt) { while ($row = db2_fetch_array($stmt)) { //$query2 = "select * from(Select ROW_NUMBER() OVER() as rn, $computerName.bids.* FROM $computerName.bids) where rn between $offset and $variable"; $query2 = "Select highest_bid_amount, number_of_bids from {$computerName}.bids where item_id =" . $row[1]; $stmt2 = db2_prepare($connection, $query2); $result2 = db2_execute($stmt2); $row2 = db2_fetch_array($stmt2); echo "<tr>"; echo "<td><center><a href=\"product.php?id=" . $row[1] . "\"><image src='" . $row[8] . "' width = 175 height = 175 </image></a></center></td>"; echo "<td><center><a href=\"product.php?id=" . $row[1] . "\">" . $row[2] . "</a></center></td>"; echo "<td>" . $row2[0] . "</td>"; echo "<td>" . $row2[1] . "</td>"; echo "</tr>"; } } /* * **** build the pagination links ***** */ // range of num links to show $range = 2; //if not on page 1, dont show back links ?> <!--drop down menu-->
/** * 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; }
/** * Fetch the next row from the given result object, in associative array * form. Fields are retrieved with $row['fieldname']. * * @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 fetchRow($res) { if ($res instanceof ResultWrapper) { $res = $res->result; } @($row = db2_fetch_array($res)); if ($this->lastErrno()) { throw new DBUnexpectedError($this, 'Error in fetchRow(): ' . htmlspecialchars($this->lastError())); } return $row; }
} $bid = db2_fetch_array($stmt2); if (!$bid) { continue; // NOT BIDDING ITEM } // I BID // CHECK IF ENDED $sql2 = "SELECT HIGHEST_BID_AMOUNT, END_DATE, END_TIME, HIGHEST_BIDDER FROM " . $computerName . ".BIDS WHERE ITEM_ID = {$itemID} and CURRENT DATE >= END_DATE"; $stmt2 = db2_prepare($conn, $sql2); $result2 = db2_execute($stmt2); if (!$result2) { echo "exec errormsg: " . db2_stmt_errormsg($stmt2); die("Failed Query"); } $bid = db2_fetch_array($stmt2); if (!$bid) { continue; } $endTime = $bid[1] . ' ' . $bid[2]; $curTime = date("Y-m-d H:i:s"); if (strcmp($endTime, $curTime) > 0) { continue; } $endTime = $bid[1] . ' ' . $bid[2]; $highestBid = $bid[0]; $highestBidder = $bid[3]; $condition = $row[3]; $desc = $row[2] . '<br><br> Condition: ' . $row[3] . '<br>Item #' . $itemID; if (strcmp($highestBidder, $userName) == 0) { $bidStatus = 'Winning Bidder';
function dbFetchArray($conn, $result) { return db2_fetch_array($result); }