Php connects to the oracle database and queries data SQL

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.