How PHP connects to Oracle database and query data, Oracle Database _php Tutorial

Source: Internet
Author: User

How PHP connects to Oracle database and query data, Oracle database


This article explains how PHP connects to Oracle database and query data. Share to everyone for your reference. The specific analysis is as follows:

PHP has a powerful capability not only to support mysql,mssql,mysqli we can also connect with Oracle data, to make PHP support Oracle very simple we just put php.ini in; extention = Php_ The Oci8.dll semicolon is removed.

PHP supports Oracle connection functions

php.ini file configuration, remove; extention = Php_oci8.dll, remove the front semicolon, restart Apache, if not, we will put the PHP directory Php_ Oci8.dll to the Windows system under the System32.

The Oracle database establishes a link with the following code:

1.Copy CodeThe code is as follows: $conn = Oci_connect (' username ', ' password ', "(description= (address= PROTOCOL) (=tcp) (PORT = 1521)) (Connect_data = (sid=test)));
2.Copy CodeThe code is as follows: $conn = Oci_connect (' username ', ' password ', ' 192.168.1.100/test ');
3.Oracle Connection method:
Copy CodeThe 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:
Copy CodeThe 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 way not, using the second, the inside of a few parameters are user name, password, Oracle service address, where test is the service name, the code is as follows:
Copy CodeThe code is as follows: $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 "
";
}
To see a complete example, if PHP version >5.0, then use the following function:
Copy CodeThe code is as follows: Oci_connect (username, password, dbname)
example, the code is as follows:
Copy CodeThe 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 statements
$stid = Oci_parse ($conn, $query); Configure SQL statements to prepare for execution
if (! $stid) {
$e = Oci_error ($conn);
Print htmlentities ($e [' message ']);
Exit
}
$r = Oci_execute ($stid, Oci_default); Execute SQL. Oci_default says no automatic commit
if (! $r) {
$e = Oci_error ($stid);
Echo htmlentities ($e [' message ']);
Exit
}
Print execution Results
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 is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/934925.html www.bkjia.com true http://www.bkjia.com/PHPjc/934925.html techarticle PHP connection to Oracle database and query data methods, Oracle database This article describes the PHP connection to the Oracle database and query data methods. Share to everyone for your reference. Specific analysis ...

  • 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.