Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head><style>*{font-family:Verdana}table,td,th{border-collapse:collapse;border:1px solid lightgray}</style></head>
- <body>
- <h1>pdo</h1>
- <sup>http://www.learn-coding.today/php_pdo_oracle.php</sup><br>
- <?php
- #$param = $_POST;
- $db_username = "guest";
- $db_password = "guest";
- $db = "oci:dbname=XE";
- try {
- $conn = new PDO($db,$db_username,$db_password);
- #$name = $param['module'];
- #$file = $param['file'];
- #$stmt = $conn->exec("INSERT INTO AL_MODULE (AL_MODULENAME, AL_MODULEFILE) VALUES ('$name', '$file')");
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->query('SELECT * FROM takaros_hrszek WHERE ROWNUM < 5');
- while ($row = $stmt->fetch())
- {
- echo $row[0] .", ". $row[1] . ", " . $row[2] .", " . $row[3] .", " . $row[4] ."<br>";
- }
- } catch(PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- ?>
- <h1>oci</h1>
- <?php
- // Create connection to Oracle
- $conn = oci_connect("guest", "guest", "localhost/XE");
- if (!$conn) {
- $m = oci_error();
- echo $m['message'], "\n";
- exit;
- }
- else {
- print "Connected to Oracle!";
- }
- // Close the Oracle connection
- oci_close($conn);
- ?>
- <h1>oci+</h1>
- <?php
- $conn = oci_connect('guest', 'guest', 'localhost/XE');
- if (!$conn) {
- $e = oci_error();
- trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
- }
- $stid = oci_parse($conn, 'SELECT * FROM takaros_hrszek WHERE ROWNUM < 5');
- oci_execute($stid);
- $nrows = oci_fetch_all($stid, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW);
- echo "<p>".var_dump($res)."</p>";
- // var_dump output is:
- // 2 rows fetched
- // array(2) {
- // ["POSTAL_CODE"]=>
- // array(2) {
- // [0]=>
- // string(6) "00989x"
- // [1]=>
- // string(6) "10934x"
- // }
- // ["CITY"]=>
- // array(2) {
- // [0]=>
- // string(4) "Roma"
- // [1]=>
- // string(6) "Venice"
- // }
- // }
- // Pretty-print the results
- echo "<table>\n";
- echo "<tr>";
- for ($i = 1; $i <= oci_num_fields($stid); $i++) {
- echo "<th>".oci_field_name($stid, $i)."</th>";
- }
- echo "</tr>\n";
- foreach ($res as $col) {
- echo "<tr>\n";
- foreach ($col as $item) {
- echo " <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "")."</td>";
- }
- echo "\n</tr>\n";
- }
- echo "</table>\n";
- echo "$nrows rows fetched<br>\n";
- oci_free_statement($stid);
- oci_close($conn);
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment