Guest User

Untitled

a guest
Dec 2nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. function exec_query($sql, $params = []) {
  3. $username = 's1165683';
  4. $password = '11656830';
  5. $conn_info = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) " .
  6. "(HOST = oracleacademy.ouhk.edu.hk)(PORT=8998)) " .
  7. "(CONNECT_DATA=(SERVER=DEDICATED) " .
  8. "(SID=db1011)))";
  9. $conn = oci_connect($username, $password, $conn_info);
  10. if (!$conn) {
  11. $e = oci_error();
  12. die("Fatal: Unable to connect to the database: {$e['message']}");
  13. }
  14. $stmt = oci_parse($conn, $sql);
  15. if (!$stmt) {
  16. die("Fatal: Failed to parse SQL statement: $sql");
  17. }
  18. foreach ($params as $key => &$value) {
  19. if (!oci_bind_by_name($stmt, ":" . $key, $value)) {
  20. die ("Fatal: Failed to bind variable $key: $sql");
  21. }
  22. }
  23. if (!@oci_execute($stmt)) {
  24. $err = oci_error($stmt);
  25. die("Fatal: Unable to execute SQL statement: {$e['message']}");
  26. }
  27. $result = [];
  28. while ($raw_row = @oci_fetch_assoc($stmt)) {
  29. $row = [];
  30. foreach ($raw_row as $k => $v) {
  31. $row[strtolower($k)] = $v;
  32. }
  33. $result[] = $row;
  34. }
  35. oci_free_statement($stmt);
  36. oci_close($conn);
  37. return $result;
  38. }
Add Comment
Please, Sign In to add comment