Php has powerful functions that not only support mysql, mssql, and mysqli, we can also connect to oracle Data. to make php support for oracle very simple, we just need to put php. extention... php has powerful functions that not only support mysql, mssql, and mysqli, we can also connect to oracle Data. to make php support for oracle very simple, we just need to put php. in ini, remove the; extention = php_oci8.dll semicolon.
Php supports oracle connection functions
Php. in the INI file, remove the configuration; extention = php_oci8.dll, remove the semicolon, and restart apache. if not, copy php_oci8.dll in the php directory to system32 in windows.
The code for creating a connection to the oracle database is as follows:
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 method does not work. The second method is used. the parameters are the user name, password, and oracle service address. test is the service name and the code is as follows:
$ SQL = "select * from table_exmaple" $ ora_test = oci_parse ($ conn, $ SQL); // compile the SQL statement oci_execute ($ ora_test, OCI_DEFAULT ); // execute while ($ r = oci_fetch_row ($ ora_test) // Retrieve the result {echo $ ora_test [0]; echo"
";}
Take a complete example. If PHP version is later than 5.0, use the following function:
oci_connect ( username, password , dbname )
The code is as follows:
'; While ($ row = oci_fetch_array ($ stid, OCI_RETURN_NULLS) {print''; Foreach ($ row as $ item) {print''. ($ Item? Htmlentities ($ item ):'').'';} Print'';} Print''; Oci_close ($ conn );
Article link:
Save this article for favorites!