Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function exec_query($sql, $params = []) {
- $username = 's1165683';
- $password = '11656830';
- $conn_info = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) " .
- "(HOST = oracleacademy.ouhk.edu.hk)(PORT=8998)) " .
- "(CONNECT_DATA=(SERVER=DEDICATED) " .
- "(SID=db1011)))";
- $conn = oci_connect($username, $password, $conn_info);
- if (!$conn) {
- $e = oci_error();
- die("Fatal: Unable to connect to the database: {$e['message']}");
- }
- $stmt = oci_parse($conn, $sql);
- if (!$stmt) {
- die("Fatal: Failed to parse SQL statement: $sql");
- }
- foreach ($params as $key => &$value) {
- if (!oci_bind_by_name($stmt, ":" . $key, $value)) {
- die ("Fatal: Failed to bind variable $key: $sql");
- }
- }
- if (!@oci_execute($stmt)) {
- $err = oci_error($stmt);
- die("Fatal: Unable to execute SQL statement: {$e['message']}");
- }
- $result = [];
- while ($raw_row = @oci_fetch_assoc($stmt)) {
- $row = [];
- foreach ($raw_row as $k => $v) {
- $row[strtolower($k)] = $v;
- }
- $result[] = $row;
- }
- oci_free_statement($stmt);
- oci_close($conn);
- return $result;
- }
Add Comment
Please, Sign In to add comment