PHP Database connection

Source: Internet
Author: User
Tags connect mysql php and php and mysql php database query oracle database

With PHP you can easily connect to the database, request the data and display it in your Web site, or even modify the data in the database. MySQL is a very popular database, and there are many tutorials about PHP and MySQL on the internet. MySQL is free, which may attract a lot of people. Because of its wide application, I do not want to repeat the use of MySQL here. Oracle is heavily used in enterprise applications, so we use Oracle to introduce PHP's connection to the database. We certainly don't mention the Oracle database design because it's beyond the scope of our discussion.

PHP provides two sets of functions that are connected to Oracle, namely the Ora_ and OCI functions. Where the Ora_ function is slightly stale. The OCI function update is said to be better. The use of the syntax is almost the same. As mentioned earlier, your PHP installation options should be able to support both use.

For more information on installing the PHP3 Apache server on a Microsoft Windows platform and more about Oracle databases, consult the following url:www.csoft.net/~vsbabu/articles/oraphp.html.

4.1 Connections

if ($conn =ora_logon ("User@tnsname", "password"))

{

echo "SUCCESS! Connected to database\n ";

}

Else

{

echo "Failed:-( Could not connect to database\n ";

}

Ora_logoff ($conn);

Phpinfo ();

?>

The above code connects to the database using the Oracle database name, user name, and password defined by Tnsname (indicated in your Tnsnames.ora file). On the basis of a successful connection, the Ora_logon function returns a Non-zero connection ID and stores it in the variable $conn.

4.2 Query

Assuming the database is already connected, let's actually apply the query to the database. The following code shows a typical example of a connection and query:

The following is a reference fragment:

/*

* Connect to the database and execute the query

*/

function Printoraerr ($in _cur)

{

Check Oracle for errors

Display if there is an error

Call this function every time Oracle is requested when the pointer is activated

1 2 3 4 5 Next > Full text reading tips: Try the "←→" button, turn the page more convenient Oh!

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.