Execute queries in Oracle with PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ //fetch the data from oracle using the PHP. <html> <head> <title>ora_exec</title> </head> <body> <? //in case these aren't set for httpd putenv("ORACLE_HOME=/usr/local/oracle7"); putenv("ORACLE_SID=ORCL"); function reportError($id, $message) { print("$message<br />\n"); print("Error Code: " . ora_errorcode($id) . "<br />\n"); print("Error Message: " . ora_error($id) . "<br />\n"); } //connect to server if(!($Connection = ora_logon("scott", "tiger"))) { print("Could not connect to database!<br />\n"); exit; } //open cursor if(!($Cursor = ora_open($Connection))) { reportError($Connection, "Cursor could not be opened!"); exit; } $Query = "SELECT * "; $Query .= "FROM emp "; //parse query if(!ora_parse($Cursor, $Query)) { reportError($Cursor, "Statement could not be parsed!"); exit; } // execute query if(!ora_exec($Cursor)) { reportError($Cursor, "Statement could not be executed!"); exit; } //start table print("<table BORDER=\"1\">\n"); //print header row that describes each column print("<tr>\n"); for($i = 0; $i < ora_numcols($Cursor); $i++) { print("<th>"); // get column info print(ora_columnname($Cursor, $i) . ": "); print(ora_columntype($Cursor, $i) . " "); print("(" . ora_columnsize($Cursor, $i) . ")"); print("</th>\n"); } print("</tr>\n"); // get each row while(ora_fetch($Cursor)) { print("<tr>\n"); //loop over each column for($i = 0; $i < ora_numcols($Cursor); $i++) { print("<td>"); // get column print(ora_getcolumn($Cursor, $i)); print("</td>\n"); } print("</tr>\n"); } //close table print("</table>\n"); print("<br />\n"); print("Rows: " . ora_numrows($Cursor)); print("<br />\n"); // Close the Oracle cursor ora_close($Cursor); // disconnect. ora_logoff($Connection); ?> </body> </html> |