Last active
November 5, 2018 18:10
-
-
Save allanjos/2d8eee09e1b375177722e8644417141c to your computer and use it in GitHub Desktop.
Oracle database connection from PHP language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo 'Oracle connection test<br/>'; | |
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA=(SERVICE_NAME=orcl.olivum.local)))" ; | |
if ($connection = OCILogon("userweb", "passcode", $db)) { | |
echo "Successfully connected to Oracle.<br/>"; | |
} | |
else { | |
$err = OCIError(); | |
echo "Connection failed.". $err[text]; | |
return; | |
} | |
$query = "SELECT * FROM product"; | |
echo 'Query: ', $query, '<br/>'; | |
$result = oci_parse($connection, $query); | |
oci_execute($result); | |
echo 'Records:<br/>'; | |
while ($row = oci_fetch_array($result, OCI_ASSOC)) { | |
#var_dump($row); | |
echo 'ID=', $row['NAME'], ', NAME=', $row['NAME'], '<br/>'; | |
} | |
OCILogoff($connection); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment