Php connection to the oracle database and data query methods, oracle Database _ PHP Tutorial

Source: Internet
Author: User
Php connects to the oracle database and queries data in the oracle database. Php connects to the oracle database and queries data. This article describes how to connect php to the oracle database and query data. Share it with you for your reference. Specific analysis of php connection to the oracle database and data query methods, oracle Database

This article describes how to connect php to the oracle database and query data. Share it with you for your reference. The specific analysis is as follows:

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.

The code is as follows:

$ Conn = oci_connect ('username', 'password', "(DEscriptION = (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.1.100) (PORT = 1521 )) (CONNECT_DATA = (SID = test )))");


2.

The code is as follows:

$ Conn = oci_connect ('username', 'password', '192. 168.1.100/test ');


3. Oracle connection method:

The code is as follows:

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:

The code is as follows:

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:

The code is as follows:

$ SQL = "select * from table_exmaple"
$ Ora_test = oci_parse ($ conn, $ SQL); // compile an 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:

The code is as follows:

Oci_connect (username, password, dbname)


The code is as follows:

The code is as follows:

<? 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); // Configure the SQL statement and prepare for execution.
If (! $ Stid ){
$ E = oci_error ($ conn );
Print htmlentities ($ e ['message']);
Exit;
}
$ R = oci_execute ($ stid, OCI_DEFAULT); // run the SQL statement. OCI_DEFAULT indicates that automatic commit is not allowed.
If (! $ R ){
$ E = oci_error ($ stid );
Echo htmlentities ($ e ['message']);
Exit;
}
// Print the execution result
Print'









';While ($ row = oci_fetch_array ($ stid, OCI_RETURN_NULLS )){Print' ';Foreach ($ row as $ item ){Print' ';}Print' ';}Print'
'. ($ Item? Htmlentities ($ item ):'').'
';
Oci_close ($ conn );
?>

I hope this article will help you with php programming.

This article describes how to connect php to the oracle database and query data. Share it with you for your reference. Specific analysis...

Related Article

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.