public function fetch_row() { if ($this->flags['fetch_all_rows']) { return false; } if ($this->num_fields) { $this->flags['fetch_row']++; return @db2_fetch_assoc($this->resource); } return false; }
function updateTicket() { // connect db=> stmt sql => insert => refresh page if (isset($_POST['id_value'])) { $transID = $_POST['id_value']; } $conn = dbConnect(); // start connect db if ($conn) { $update = "UPDATE EMM_ZOO.TICKETTRANS_TRANSACTION SET TICKETTRANS_TIMEIN = CURRENT TIME WHERE TICKETTRANS_ID = " . $transID . ";"; //echo $update; $rc = db2_exec($conn, $update); if ($rc) { //header("Refresh:0; url=TranspotationIN.php"); } else { // If statement is error why see the code die('Critical error:' . db2_stmt_error($stmt)); } // finish all query statement db2_free_stmt($rc); $sql = "SELECT * FROM EMM_ZOO.TICKETTRANS_TRANSACTION JOIN EMM_ZOO.TICKETTRANS_TYPE ON VEHICLETRANS_ID = TRANSTYPE_ID WHERE TICKETTRANS_ID = " . $transID . ";"; $stmt = db2_exec($conn, $sql); while ($row = db2_fetch_assoc($stmt)) { $tran_price = $row['TRANSTYPE_PRICE']; $tran_type = $row['TRANSTYPE_NAME']; $hourOut = (int) substr($row['TICKETTRANS_TIMEOUT'], 0, 2); $hourIn = (int) substr($row['TICKETTRANS_TIMEIN'], 0, 2); $extraOut = (int) substr($row['TICKETTRANS_TIMEOUT'], 3, 2); $extraIn = (int) substr($row['TICKETTRANS_TIMEIN'], 3, 2); $price = ($hourIn - $hourOut) * $tran_price; // ราคาต้องดึงมาจาก trans_Type table if ($extraIn - $extraOut > 0) { $price += $tran_price; } if ($extraIn - $extraOut == 0 && $hourIn - $hourOut == 0 && (int) substr($row['TICKETTRANS_TIMEOUT'], 6, 2) != (int) substr($row['TICKETTRANS_TIMEIN'], 6, 2)) { $price += $tran_price; } if ($stmt) { // echo "Insert successfully!!"; echo "<script>alert('Price of {$tran_type} is {$price}');window.location='TranspotationIN.php';</script>"; //header("Refresh:0; url=TranspotationIN.php"); } else { // If statement is error why see the code die('Critical error:' . db2_stmt_error($stmt)); } } db2_free_stmt($rc); db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
/** * @param String strSQL * @return Array */ public function db_getfieldslist($table) { $res = array(); $arr = implode(".", $table); $stmt = db2_columns($this->connectionObj->conn, null, $arr[0], $arr[1], '%'); if ($stmt) { while ($rowC = db2_fetch_assoc($stmt)) { $ntype = $this->getFieldTypeNumber($rowC["TYPE_NAME"]); $res[$i] = array("fieldname" => $rowC["COLUMN_NAME"], "type" => $ntype, "is_nullable" => 0); } } return $res; }
function updateTicket() { // connect db=> stmt sql => insert => refresh page if (isset($_POST)) { $type[0] = $_POST['typeC']; $type[1] = $_POST['typeA']; $type[2] = $_POST['typeF']; $num[0] = intval($_POST['TicketNumC']); $num[1] = intval($_POST['TicketNumA']); $num[2] = intval($_POST['TicketNumF']); //$num = $_POST['TicketNum']; } // start connect db $conn = dbConnect(); if ($conn) { //Part one select data from tickettype for ($i = 0; $i <= 2; $i++) { if ($num[$i] == 0) { continue; } $sql = "SELECT * FROM EMM_ZOO.TICKETGATE_TYPE WHERE TICKETGATE_TYPE = '{$type[$i]}';"; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); while ($row = db2_fetch_assoc($stmt)) { $ticket_price = $row['TICKETGATETYPE_PRICE']; $ticket_type = $row['TICKETGATE_TYPE']; $ticket_id = intval($row['TICKETGATETYPE_ID']); //printf ("%-5d %-16s %-32d\n", // $ticket_price, $ticket_type, $ticket_id); } $insert = "INSERT INTO EMM_ZOO.TICKETGATE_TRANSACTION (TICKETGATE_ID, TICKETGATETYPE_ID, TICKETGATE_DATE, TICKETGATE_NUM, TICKETGATE_PRICE) VALUES (DEFAULT, {$ticket_id}, CURRENT DATE, {$num[$i]}" . "," . $ticket_price * $num[$i] . ");"; //echo $insert; $rc = db2_exec($conn, $insert); // ตรงนี้ error ยังไม่เสร็จ if ($rc) { // echo "Insert successfully!!"; echo "<script>alert('{$num[$i]} {$type[$i]} ticket has sole in price " . $ticket_price * $num[$i] . "');window.location='GateTricket.php';</script>"; } else { // If statement is error why see the code die('Critical error:' . db2_stmt_error($stmt)); } // finish all query statement db2_free_stmt($stmt); } db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
function addRound() { if (isset($_POST)) { $showID = $_POST['showID']; $roundID = $_POST['roundID']; $starttime = $_POST['starttime']; $endtime = $_POST['endtime']; $showdate = $_POST['showdate']; } $conn = dbConnect(); if ($conn) { $insert = "INSERT INTO EMM_ZOO.SHOW_TIMETABLE(SHOWID, ROUNDID, STARTTIME, ENDTIME, DATES) values({$showID}, {$roundID}, '{$starttime}', '{$endtime}', '{$showdate}');"; //$insert = "INSERT INTO EMM_ZOO.SHOW_TIMETABLE(SHOWID, ROUNDID, STARTTIME, ENDTIME, DATES) values(1, 3, '16:00:00', '16:30:00', '11/12/2015');"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Insert Successful"; } else { die('Critical error: ' . db2_stmt_error($rc)); } $sql = "SELECT * from EMM_ZOO.SHOW WHERE SHOWID = {$showID};"; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); while ($row = db2_fetch_assoc($stmt)) { $zone = $row['BUILDINGID']; $name = $row['SHOWNAME']; } $insert = "INSERT INTO EMM_ZOO.SHOW_TICKET(SHOWID, STARTTIME, ENDTIME, DATES, SHOWNAME, ZONEID) values({$showID}, '{$starttime}', '{$endtime}', '{$showdate}', '{$name}', {$zone});"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Insert Successful"; } else { die('Critical error: ' . db2_stmt_error($rc)); } db2_free_stmt($stmt); db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
function updateTicket() { // connect db=> stmt sql => insert => refresh page if (isset($_POST)) { $type = $_POST['type']; } // start connect db $conn = dbConnect(); if ($conn) { //Part one select data from tickettype $sql = "SELECT * FROM EMM_ZOO.TICKETTRANS_TYPE WHERE TRANSTYPE_NAME = '{$type}';"; //echo $sql; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); while ($row = db2_fetch_assoc($stmt)) { $tran_price = $row['TRANSTYPE_PRICE']; $tran_type = $row['TRANSTYPE_NAME']; $tran_id = $row['TRANSTYPE_ID']; // printf ("%-5d %-16s %-32d\n", // $tran_price, $tran_type, $tran_id); } $insert = " INSERT INTO EMM_ZOO.TICKETTRANS_TRANSACTION (TICKETTRANS_ID, VEHICLETRANS_ID, TICKETTRANS_DATE , TICKETTRANS_TIMEIN ,TICKETTRANS_TIMEOUT) VALUES (DEFAULT, '{$tran_id}',CURRENT DATE , NULL, CURRENT TIME);"; $rc = db2_exec($conn, $insert); if ($rc) { echo "<script>alert('1 {$tran_type} has rent');window.location='TranspotationTricket.php';</script>"; } else { // If statement is error why see the code die('Critical error:' . db2_stmt_error($stmt)); } // finish all query statement db2_free_stmt($stmt); db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
/** * 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; }
/** * Executes an SQL query * * @param string|fStatement $statement The statement to perform * @param fResult $result The result object for the query * @param array $params The parameters for prepared statements * @return void */ private function performQuery($statement, $result, $params) { fCore::startErrorCapture(); $extra = NULL; if (is_object($statement)) { $statement->executeQuery($result, $params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $extra = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY)); if (is_resource($extra)) { $rows = array(); while ($row = db2_fetch_assoc($extra)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $result->getSQL()); if ($extra && oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { oci_fetch_all($extra, $rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC); $result->setResult($rows); unset($rows); } else { $result->setResult(FALSE); } } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $extra)); } elseif ($this->extension == 'sqlsrv') { $extra = sqlsrv_query($this->connection, $result->getSQL()); if (is_resource($extra)) { $rows = array(); while ($row = sqlsrv_fetch_array($extra, SQLSRV_FETCH_ASSOC)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'pdo') { if (preg_match('#^\\s*CREATE(\\s+OR\\s+REPLACE)?\\s+TRIGGER#i', $result->getSQL())) { $this->connection->exec($result->getSQL()); $extra = FALSE; $returned_rows = array(); } else { $extra = $this->connection->query($result->getSQL()); if (is_object($extra)) { // This fixes a segfault issue with blobs and fetchAll() for pdo_ibm if ($this->type == 'db2') { $returned_rows = array(); while (($row = $extra->fetch(PDO::FETCH_ASSOC)) !== FALSE) { foreach ($row as $key => $value) { if (is_resource($value)) { $row[$key] = stream_get_contents($value); } } $returned_rows[] = $row; } // pdo_dblib doesn't throw an exception on error when executing // a prepared statement when compiled against FreeTDS, so we have // to manually check the error info to see if something went wrong } elseif ($this->type == 'mssql' && !fCore::checkOS('windows') && preg_match('#^\\s*EXEC(UTE)?\\s+#i', $result->getSQL())) { $error_info = $extra->errorInfo(); if ($error_info && strpos($error_info[2], '(null) [0] (severity 0)') !== 0) { $returned_rows = FALSE; } } else { $returned_rows = $extra->fetchAll(PDO::FETCH_ASSOC); } } else { $returned_rows = $extra; } // The pdo_pgsql driver likes to return empty rows equal to the number of affected rows for insert and deletes if ($this->type == 'postgresql' && $returned_rows && $returned_rows[0] == array()) { $returned_rows = array(); } } $result->setResult($returned_rows); } $this->statement = $statement; $this->handleErrors(fCore::stopErrorCapture()); // The mssql extension will sometimes not return FALSE even if there are errors if (strlen($this->error) && strpos($this->error, 'WARNING!') !== 0) { $result->setResult(FALSE); } $this->checkForError($result, $extra); if ($this->extension == 'mssql') { $this->error = ''; } if ($this->extension == 'ibm_db2') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { db2_free_result($extra); } } elseif ($this->extension == 'pdo') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { $extra->closeCursor(); } } elseif ($this->extension == 'oci8') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { oci_free_statement($extra); } } elseif ($this->extension == 'sqlsrv') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { sqlsrv_free_stmt($extra); } } else { $this->setAffectedRows($result, $extra); } $this->setReturnedRows($result); $this->handleAutoIncrementedValue($result, $extra); }
$sqlGuide = "SELECT FIRSTNAME, LASTNAME FROM EMM_ZOO.TOUR_GUIDE WHERE GUIDEID = ?"; $stmtGuide = db2_prepare($conn, $sqlGuide); db2_bind_param($stmtGuide, 1, $gID); db2_execute($stmtGuide); ?> <tr> <td class=""><?php echo $id; ?> </td> <td class=""><?php echo $name; ?> </td> <?php while ($row = db2_fetch_assoc($stmtGuide)) { $gName = $row['FIRSTNAME'] . " " . $row['LASTNAME']; ?> <td class=""><?php echo $gName; ?> </td> <?php } ?> <td class=""><?php echo $amount; ?> </td> <td class="last"><a href="#">View</a> </td>
public static function fetch_assoc($psql, $conn) { if ($psql) { return db2_fetch_assoc($psql); } return false; }
function addShow() { if (isset($_POST)) { $showName = $_POST['showName']; $animalID = $_POST['animalID']; $staffID = $_POST['staffID']; $buildingID = $_POST['buildingID']; $seat = $_POST['seat']; $price = $_POST['price']; } $conn = dbConnect(); if ($conn) { $sql = "SELECT EMPID FROM EMM_ZOO.EMPLOYEE WHERE EMPID = " . $staffID; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); $count = 0; while ($row = db2_fetch_assoc($stmt)) { $count++; } if ($count <= 0) { echo "Wrong Staff ID."; } else { // Query db2_free_stmt($stmt); $sql = "SELECT ANIMALID FROM EMM_ZOO.ANIMAL WHERE ANIMALID = " . $animalID; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); $count = 0; while ($row = db2_fetch_assoc($stmt)) { $count++; } if ($count <= 0) { echo "Wrong Animal ID."; } else { $insert = "INSERT INTO EMM_ZOO.SHOW(SHOWID, SHOWNAME, BUILDINGID, SEAT_AMOUNT, PRICE) values(DEFAULT, '{$showName}', {$buildingID}, {$seat}, {$price});"; $rc = db2_exec($conn, $insert); if ($rc) { db2_free_stmt($stmt); $sql = "SELECT SHOWID from EMM_ZOO.SHOW;"; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); while ($row = db2_fetch_assoc($stmt)) { $show_showID = $row['SHOWID']; } $insert = "INSERT INTO EMM_ZOO.SHOW_ANIMAL (SHOWID, ANIMALID) VALUES ({$show_showID}, {$animalID});"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Insert Successful"; } else { die('Critical error: ' . db2_stmt_error($stmt)); } $insert = "INSERT INTO EMM_ZOO.SHOW_STAFF (SHOWID, EMPID) VALUES ({$show_showID}, {$staffID});"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Insert Successful"; } else { die('Critical error: ' . db2_stmt_error($stmt)); } /* $insert = "INSERT INTO EMM_ZOO.SHOW_TICKET (SHOWID, SHOWNAME, BUILDINGID) VALUES ($show_showID, '$showName', $buildingID);"; $rc=db2_exec($conn, $insert); if($rc) { echo "Insert Successful"; } else { die('Critical error: '. db2_stmt_error($stmt)); }*/ } else { } } } db2_free_stmt($stmt); db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
/** * 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; }
/** * {@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."); } }
/** * Executes an SQL query * * @param string|fStatement $statement The statement to perform * @param fResult $result The result object for the query * @param array $params The parameters for prepared statements * @return void */ private function performQuery($statement, $result, $params) { $this->setErrorHandler(); $extra = NULL; if (is_object($statement)) { $statement->executeQuery($result, $params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $extra = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY)); if (is_resource($extra)) { $rows = array(); while ($row = db2_fetch_assoc($extra)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $result->getSQL()); if (oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { oci_fetch_all($extra, $rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC); $result->setResult($rows); unset($rows); } else { $result->setResult(FALSE); } } elseif ($this->extension == 'odbc') { $extra = odbc_exec($this->connection, $result->getSQL()); if (is_resource($extra)) { $rows = array(); // Allow up to 1MB of binary data odbc_longreadlen($extra, 1048576); odbc_binmode($extra, ODBC_BINMODE_CONVERT); while ($row = odbc_fetch_array($extra)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $extra)); } elseif ($this->extension == 'sqlsrv') { $extra = sqlsrv_query($this->connection, $result->getSQL()); if (is_resource($extra)) { $rows = array(); while ($row = sqlsrv_fetch_array($extra, SQLSRV_FETCH_ASSOC)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'pdo') { if (preg_match('#^\\s*CREATE(\\s+OR\\s+REPLACE)?\\s+TRIGGER#i', $result->getSQL())) { $this->connection->exec($result->getSQL()); $extra = FALSE; $returned_rows = array(); } else { $extra = $this->connection->query($result->getSQL()); $returned_rows = is_object($extra) ? $extra->fetchAll(PDO::FETCH_ASSOC) : $extra; // The pdo_pgsql driver likes to return empty rows equal to the number of affected rows for insert and deletes if ($this->type == 'postgresql' && $returned_rows && $returned_rows[0] == array()) { $returned_rows = array(); } } $result->setResult($returned_rows); } $this->statement = $statement; $this->restoreErrorHandler(); $this->checkForError($result, $extra); if ($this->extension == 'ibm_db2') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { db2_free_result($extra); } } elseif ($this->extension == 'pdo') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { $extra->closeCursor(); } } elseif ($this->extension == 'oci8') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { oci_free_statement($extra); } } elseif ($this->extension == 'odbc') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { odbc_free_result($extra); } } elseif ($this->extension == 'sqlsrv') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { sqlsrv_free_stmt($extra); } } else { $this->setAffectedRows($result, $extra); } $this->setReturnedRows($result); $this->handleAutoIncrementedValue($result, $extra); }
/** * fetch_assoc() * * This function fetches a result as an associative array. * * @param mixed $result * @return array * @access public * @author Thorsten Rinne <*****@*****.**> * @since 2005-04-16 */ function fetch_assoc($result) { $_result = db2_fetch_assoc($result); if (is_array($_result)) { return array_change_key_case($_result, CASE_LOWER); } else { return false; } }
protected function db2FetchRow($result) { $row = db2_fetch_assoc($result); if (!$row) { return false; } if ($this->checkDB2STMTerror($result) == false) { $temp = $row; $row = array(); foreach ($temp as $key => $val) { // make the column keys as lower case. Trim the val returned $row[strtolower($key)] = is_string($val) ? trim($val) : $val; } } else { return false; } return $row; }
function editShow() { if (isset($_POST)) { $showID = $_POST['showID']; $showName = $_POST['showName']; $animalID = $_POST['animalID']; $staffID = $_POST['staffID']; $buildingID = $_POST['buildingID']; $seat = $_POST['seat']; $price = $_POST['price']; } $conn = dbConnect(); if ($conn) { $sql = "SELECT EMPID FROM EMM_ZOO.EMPLOYEE WHERE EMPID = " . $staffID; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); $count = 0; while ($row = db2_fetch_assoc($stmt)) { $count++; } if ($count <= 0) { echo "Wrong Staff ID."; } else { // Query db2_free_stmt($stmt); $sql = "SELECT ANIMALID FROM EMM_ZOO.ANIMAL WHERE ANIMALID = " . $animalID; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); $count = 0; while ($row = db2_fetch_assoc($stmt)) { $count++; } if ($count <= 0) { echo "<script>alert(Wrong Animal ID.);</script>"; header("Location:index.php"); } else { $insert = "UPDATE EMM_ZOO.SHOW SET SHOWNAME='{$showName}', BUILDINGID={$buildingID}, SEAT_AMOUNT={$seat}, PRICE={$price} WHERE SHOWID = {$showID};"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Update Successful"; } else { die('Critical error: ' . db2_stmt_error($stmt)); } $insert = "UPDATE EMM_ZOO.SHOW_ANIMAL SET ANIMALID = {$animalID} WHERE SHOWID = {$showID}"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Update Successful"; } else { die('Critical error: ' . db2_stmt_error($stmt)); } $insert = "UPDATE EMM_ZOO.SHOW_STAFF SET EMPID = {$staffID} WHERE SHOWID = {$showID};"; $rc = db2_exec($conn, $insert); if ($rc) { echo "Update Successful"; } else { die('Critical error: ' . db2_stmt_error($stmt)); } } } db2_free_stmt($stmt); db2_close($conn); } else { echo db2_conn_errormsg($conn); } }
/** * Creates an array with all table names * * @return void * @access public * @author Matteo Scaramuccia <*****@*****.**> * @author Thorsten Rinne <*****@*****.**> * @since 2006-08-26 */ function getTableNames($prefix = '') { $stmt = db2_tables($this->conn); while ($table = db2_fetch_assoc($stmt)) { if ($table['TABLE_TYPE'] == 'TABLE' && strstr($table['TABLE_NAME'], $prefix . 'FAQ')) { $this->tableNames[] = $table['TABLE_NAME']; } } }
/** * {@inheritdoc} */ public function fetch($sql) { $data = []; $stmt = db2_prepare($this->connection, $sql); $this->result = db2_execute($stmt); while ($row = db2_fetch_assoc($stmt)) { $data[] = $row; } return $data; }
/** * Returns the next data set from a DB resource or false if there are no more results. * * @param resource $cursor * @param bool $convertNulls convert all null values to string zeroes * * @return array|bool */ function DBfetch($cursor, $convertNulls = true) { global $DB; $result = false; if (!isset($DB['DB']) || empty($DB['DB']) || is_bool($cursor)) { return $result; } switch ($DB['TYPE']) { case ZBX_DB_MYSQL: $result = mysqli_fetch_assoc($cursor); if (!$result) { mysqli_free_result($cursor); } break; case ZBX_DB_POSTGRESQL: if (!($result = pg_fetch_assoc($cursor))) { pg_free_result($cursor); } break; case ZBX_DB_ORACLE: if ($row = oci_fetch_assoc($cursor)) { $result = array(); foreach ($row as $key => $value) { $field_type = strtolower(oci_field_type($cursor, $key)); // Oracle does not support NULL values for string fields, so if the string is empty, it will return NULL // convert it to an empty string to be consistent with other databases $value = str_in_array($field_type, array('varchar', 'varchar2', 'blob', 'clob')) && is_null($value) ? '' : $value; if (is_object($value) && strpos($field_type, 'lob') !== false) { $value = $value->load(); } $result[strtolower($key)] = $value; } } break; case ZBX_DB_DB2: if (!($result = db2_fetch_assoc($cursor))) { db2_free_result($cursor); } else { // cast all of the values to string to be consistent with other DB drivers: all of them return // only strings. foreach ($result as &$value) { if ($value !== null) { $value = (string) $value; } } unset($value); } break; case ZBX_DB_SQLITE3: if ($DB['TRANSACTIONS'] == 0) { lock_sqlite3_access(); } if (!($result = $cursor->fetchArray(SQLITE3_ASSOC))) { unset($cursor); } else { // cast all of the values to string to be consistent with other DB drivers: all of them return // only strings. foreach ($result as &$value) { $value = (string) $value; } unset($value); } if ($DB['TRANSACTIONS'] == 0) { unlock_sqlite3_access(); } break; } if ($result) { if ($convertNulls) { foreach ($result as $key => $val) { if (is_null($val)) { $result[$key] = '0'; } } } return $result; } return false; }
/** * {@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."); } }
/** * Gets the next row from the result and assigns it to the current row * * @return void */ private function advanceCurrentRow() { $type = $this->database->getType(); switch ($this->extension) { case 'ibm_db2': $row = db2_fetch_assoc($this->result); break; case 'mssql': // For some reason the mssql extension will return an empty row even // when now rows were returned, so we have to explicitly check for this if ($this->pointer == 0 && !mssql_num_rows($this->result)) { $row = FALSE; } else { $row = mssql_fetch_assoc($this->result); if (empty($row)) { mssql_fetch_batch($this->result); $row = mssql_fetch_assoc($this->result); } if (!empty($row)) { $row = $this->fixDblibMSSQLDriver($row); } } break; case 'mysql': $row = mysql_fetch_assoc($this->result); break; case 'mysqli': if (!$this->result instanceof stdClass) { $row = mysqli_fetch_assoc($this->result); } else { $meta = $this->result->statement->result_metadata(); $row_references = array(); while ($field = $meta->fetch_field()) { $row_references[] =& $fetched_row[$field->name]; } call_user_func_array(array($this->result->statement, 'bind_result'), $row_references); $this->result->statement->fetch(); $row = array(); foreach ($fetched_row as $key => $val) { $row[$key] = $val; } unset($row_references); $meta->free_result(); } break; case 'oci8': $row = oci_fetch_assoc($this->result); break; case 'pgsql': $row = pg_fetch_assoc($this->result); break; case 'sqlite': $row = sqlite_fetch_array($this->result, SQLITE_ASSOC); break; case 'sqlsrv': $resource = $this->result instanceof stdClass ? $this->result->statement : $this->result; $row = sqlsrv_fetch_array($resource, SQLSRV_FETCH_ASSOC); break; case 'pdo': $row = $this->result->fetch(PDO::FETCH_ASSOC); if (!empty($row) && $type == 'mssql') { $row = $this->fixDblibMSSQLDriver($row); } break; } // Fix uppercase column names to lowercase if ($row && ($type == 'oracle' || $type == 'db2' && $this->extension != 'ibm_db2')) { $row = array_change_key_case($row); } // This is an unfortunate fix that required for databases that don't support limit // clauses with an offset. It prevents unrequested columns from being returned. if (isset($row['flourish__row__num'])) { unset($row['flourish__row__num']); } // This decodes the data coming out of MSSQL into UTF-8 if ($row && $type == 'mssql') { if ($this->character_set) { foreach ($row as $key => $value) { if (!is_string($value) || strpos($key, '__flourish_mssqln_') === 0 || isset($row['fmssqln__' . $key]) || preg_match('#[\\x0-\\x8\\xB\\xC\\xE-\\x1F]#', $value)) { continue; } $row[$key] = self::iconv($this->character_set, 'UTF-8', $value); } } $row = $this->decodeMSSQLNationalColumns($row); // This resets the array pointer so that // current() will work as expected reset($row); } if ($this->unescape_map) { foreach ($this->unescape_map as $column => $type) { if (!isset($row[$column])) { continue; } $row[$column] = $this->database->unescape($type, $row[$column]); } } $this->current_row = $row; }
//echo "connection status : ".$conn; //Part one select data from tickettype $sql = "SELECT * FROM EMM_ZOO.TICKETTRANS_TRANSACTION WHERE TICKETTRANS_TIMEIN IS NOT NULL ORDER BY TICKETTRANS_DATE,TICKETTRANS_TIMEOUT ;"; $stmt = db2_exec($conn, $sql); //echo $stmt; if ($stmt) { while ($row = db2_fetch_assoc($stmt)) { echo "<tr><td>" . $row['TICKETTRANS_ID'] . "</td>"; $typeId = $row['VEHICLETRANS_ID']; $sq = "SELECT * FROM EMM_ZOO.TICKETTRANS_TYPE WHERE TRANSTYPE_ID = '{$typeId}';"; //echo $sq; $stm = db2_prepare($conn, $sq); $result = db2_execute($stm); $tran_type; $tran_price; while ($ro = db2_fetch_assoc($stm)) { $tran_price = $ro['TRANSTYPE_PRICE']; $tran_type = $ro['TRANSTYPE_NAME']; // printf ("%-5d %-16s %-32d\n", // $tran_price, $tran_type, $tran_id); } echo "<td>" . $tran_type . "</td>"; echo "<td>" . $row['TICKETTRANS_DATE'] . "</td>"; echo "<td>" . $row['TICKETTRANS_TIMEOUT'] . "</td>"; echo "<td>" . $row['TICKETTRANS_TIMEIN'] . "</td>"; $hourOut = (int) substr($row['TICKETTRANS_TIMEOUT'], 0, 2); $hourIn = (int) substr($row['TICKETTRANS_TIMEIN'], 0, 2); $extraOut = (int) substr($row['TICKETTRANS_TIMEOUT'], 3, 2); $extraIn = (int) substr($row['TICKETTRANS_TIMEIN'], 3, 2); $price = ($hourIn - $hourOut) * $tran_price; // ราคาต้องดึงมาจาก trans_Type table
/** * Executes an SQL query * * @param string|fStatement $statement The statement to perform * @param fResult $result The result object for the query * @param array $params The parameters for prepared statements * @return void */ private function performQuery($statement, $result, $params) { fCore::startErrorCapture(); $extra = NULL; if (is_object($statement)) { $statement->executeQuery($result, $params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $extra = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY)); if (is_resource($extra)) { $rows = array(); while ($row = db2_fetch_assoc($extra)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'mssql') { $result->setResult(mssql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysql') { $result->setResult(mysql_query($result->getSQL(), $this->connection)); } elseif ($this->extension == 'mysqli') { $result->setResult(mysqli_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $result->getSQL()); if (oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { oci_fetch_all($extra, $rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC); $result->setResult($rows); unset($rows); } else { $result->setResult(FALSE); } } elseif ($this->extension == 'pgsql') { $result->setResult(pg_query($this->connection, $result->getSQL())); } elseif ($this->extension == 'sqlite') { $result->setResult(sqlite_query($this->connection, $result->getSQL(), SQLITE_ASSOC, $extra)); } elseif ($this->extension == 'sqlsrv') { $extra = sqlsrv_query($this->connection, $result->getSQL()); if (is_resource($extra)) { $rows = array(); while ($row = sqlsrv_fetch_array($extra, SQLSRV_FETCH_ASSOC)) { $rows[] = $row; } $result->setResult($rows); unset($rows); } else { $result->setResult($extra); } } elseif ($this->extension == 'pdo') { if (preg_match('#^\\s*CREATE(\\s+OR\\s+REPLACE)?\\s+TRIGGER#i', $result->getSQL())) { $this->connection->exec($result->getSQL()); $extra = FALSE; $returned_rows = array(); } else { $extra = $this->connection->query($result->getSQL()); if (is_object($extra)) { // This fixes a segfault issue with blobs and fetchAll() for pdo_ibm if ($this->type == 'db2') { $returned_rows = array(); $scanned_for_blobs = FALSE; $blob_columns = array(); while (($row = $extra->fetch(PDO::FETCH_ASSOC)) !== FALSE) { if (!$scanned_for_blobs) { foreach ($row as $key => $value) { if (is_resource($value)) { $blob_columns[] = $key; } } } foreach ($blob_columns as $blob_column) { $row[$blob_column] = stream_get_contents($row[$blob_column]); } $returned_rows[] = $row; } } else { $returned_rows = $extra->fetchAll(PDO::FETCH_ASSOC); } } else { $returned_rows = $extra; } // The pdo_pgsql driver likes to return empty rows equal to the number of affected rows for insert and deletes if ($this->type == 'postgresql' && $returned_rows && $returned_rows[0] == array()) { $returned_rows = array(); } } $result->setResult($returned_rows); } $this->statement = $statement; $this->handleErrors(fCore::stopErrorCapture()); $this->checkForError($result, $extra); if ($this->extension == 'ibm_db2') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { db2_free_result($extra); } } elseif ($this->extension == 'pdo') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { $extra->closeCursor(); } } elseif ($this->extension == 'oci8') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { oci_free_statement($extra); } } elseif ($this->extension == 'sqlsrv') { $this->setAffectedRows($result, $extra); if ($extra && !is_object($statement)) { sqlsrv_free_stmt($extra); } } else { $this->setAffectedRows($result, $extra); } $this->setReturnedRows($result); $this->handleAutoIncrementedValue($result, $extra); }
/** * Db2 On I5 specific method * * Returns a list of the tables in the database . * Used only for DB2/400. * * @return array */ protected function _i5listTables($schema = null) { //list of i5 libraries. $tables = array(); if ($schema) { $tablesStatement = db2_tables($this->_connection, null, $schema); while ($rowTables = db2_fetch_assoc($tablesStatement)) { if ($rowTables['TABLE_NAME'] !== null) { $tables[] = $rowTables['TABLE_NAME']; } } } else { $schemaStatement = db2_tables($this->_connection); while ($schema = db2_fetch_assoc($schemaStatement)) { if ($schema['TABLE_SCHEM'] !== null) { // list of the tables which belongs to the selected library $tablesStatement = db2_tables($this->_connection, NULL, $schema['TABLE_SCHEM']); if (is_resource($tablesStatement)) { while ($rowTables = db2_fetch_assoc($tablesStatement)) { if ($rowTables['TABLE_NAME'] !== null) { $tables[] = $rowTables['TABLE_NAME']; } } } } } } return $tables; }
/** * (PHP 5 >= 5.0.0)<br/> * Rewind the Iterator to the first element * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. */ public function rewind() { if ($this->position > 0) { throw new Exception\RuntimeException('This result is a forward only result set, calling rewind() after moving forward is not supported'); } $this->currentData = db2_fetch_assoc($this->resource); $this->currentComplete = true; $this->position = 1; }
<?php require_once '/var/www/html/app/model/connect.php'; $sql = "SELECT BUILDINGNAME FROM EMM_ZOO.BUILDING ORDER BY BUILDINGID;"; if ($conn) { $stmt = db2_exec($conn, $sql); if ($stmt) { while ($row = db2_fetch_assoc($stmt)) { print "<option value='" . $row['BUILDINGID'] . "'>" . $row['BUILDINGNAME'] . "</option>"; } } db2_free_stmt($stmt); } else { echo db2_conn_errormsg($conn); }
<meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Biological Information</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="css/style.css"> </head> <?php require_once '/var/www/html/app/model/connect.php'; $id = $_POST['Edit_species']; $sql = "SELECT * FROM EMM_ZOO.BIOINFO WHERE SPECIESID = {$id};"; #echo $id; if ($conn) { $stmt = db2_exec($conn, $sql); if ($stmt) { $row = db2_fetch_assoc($stmt); $data = array($row['SPECIESID'], $row['SPECIESNAME'], $row['PHYLUM'], $row['CLASS'], $row['ORDER'], $row['FAMILY'], $row['GENUS'], $row['WARMBLOODED'], $row['BODYCOVER'], $row['REPRODUCTION'], $row['HABITAT'], $row['COMMONFOOD'], $row['BODYTEMP'], $row['ENVITEMPRANGE'], $row['LIFESPAN']); } db2_free_stmt($stmt); } else { echo db2_conn_errormsg($conn); } ?> <body> <form type='post' method="post" name='alter_form'> <div class="container"> <form class="col s12" method="post" accept-charset="utf-8"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header">
/** * Returns a list of the tables in the database. * * @return array */ public function listTables() { $this->_connect(); // take the most general case and assume no z/OS // since listTables() takes no parameters $stmt = db2_tables($this->_connection); $tables = array(); while ($row = db2_fetch_assoc($stmt)) { $tables[] = $row['TABLE_NAME']; } return $tables; }
function animalIn() { if (isset($_POST)) { $animal = isset($_POST['animalValueForAnimalIn']) ? $_POST['animalValueForAnimalIn'] : null; $cage = isset($_POST['cageValueForAnimalIn']) ? $_POST['cageValueForAnimalIn'] : null; } $conn = dbConnect(); if ($conn) { $sql1 = "SELECT * FROM EMM_ZOO.ANIMAL WHERE ANIMALID = " . $animal . " AND CAGEID is NULL;"; $stmt = db2_exec($conn, $sql1); if ($stmt) { if ($row = db2_fetch_assoc($stmt)) { $sql2 = "INSERT INTO EMM_ZOO.ANIMALIN (ANIMALINCAGEID, ANIMALID, CAGEID, TIMEIN, OUT) VALUES (DEFAULT, " . $animal . " , " . $cage . ", current timestamp, 0);"; $rc1 = db2_exec($conn, $sql2); $sql3 = "UPDATE EMM_ZOO.ANIMAL SET CAGEID = " . $cage . " WHERE ANIMALID = '" . $animal . "';"; $rc2 = db2_exec($conn, $sql3); if ($rc1 && $rc2) { echo "<script>"; echo "alert('Successfully')"; echo "</script>"; header("Refresh:0; url=index.php"); } else { echo "<script>"; echo "alert('Failed')"; echo "</script>"; header("Refresh:0; url=index.php"); } db2_free_stmt($rc1); db2_free_stmt($rc2); } } } else { echo db2_conn_errormsg($conn); } db2_free_stmt($stmt); }