Remember that PHP supports Oracle connection functions
php.ini files in the configuration, remove; extention = Php_oci8.dll, remove the preceding semicolon
You can restart Apache,
If not, we'll copy the Php_oci8.dll in the PHP directory to the system32 under Windows System.
Oracle Database link creation
code is as follows |
copy code |
1. $conn = Oci_connect (' username ', ' password ', "(description= address= (PROTOCOL =tcp) (host=192.168.1.100) (PORT = 1521)) ( Connect_data = (sid=test))); 2. $conn = Oci_connect (' username ', ' password ', ' 192.168.1.100/test '); 3.Oracle Connection method: Set Adocon=server.createobject ("Adodb.connection") Adocon.open "Driver={microsoft ODBC for oracle};server= Oraclesever.world;uid=admin;pwd=pass; " 4.Oracle OLE DB connection method: Set Adocon=server.createobject ("Adodb.connection") Adocon.open "Provider=oraoledb.oracle;data source=dbname ; user id=admin;password=pass; " |
Sometimes the first way is not, use the second, the inside of several parameters are user name, password, Oracle service address, where test is the service name.
The code is as follows |
Copy Code |
$sql = "SELECT * FROM Table_exmaple" $ora _test = Oci_parse ($conn, $sql); Compiling SQL statements Oci_execute ($ora _test,oci_default); Perform while ($r =oci_fetch_row ($ora _test))//Retrieve results { echo $ora _test[0]; echo "<BR>"; } |
Look at a complete example.
If the PHP version >5.0, use the following function
Oci_connect (username, password, dbname)
Example:
The code is as follows |
Copy Code |
<?php $conn = Oci_connect (' hr ', ' hr ', ' ORCL '); Establish a connection if (! $conn) { $e = Oci_error (); Print htmlentities ($e [' message ']); Exit } $query = ' SELECT * from departments '; Query statement $stid = Oci_parse ($conn, $query); Configuring SQL statements, preparing to execute if (! $stid) { $e = Oci_error ($conn); Print htmlentities ($e [' message ']); Exit } $r = Oci_execute ($stid, Oci_default); Execute SQL. Oci_default says don't commit automatically if (! $r) { $e = Oci_error ($stid); Echo htmlentities ($e [' message ']); Exit } Print execution Results print ' <table border= ' 1 ' > '; while ($row = Oci_fetch_array ($stid, oci_return_nulls)) { print ' <tr> '; foreach ($row as $item) { print ' <td> '. ($item? Htmlentities ($item): '). ' </td> '; } print ' </tr> '; } print ' </table> '; Oci_close ($conn); ?> |