A piece of code sample code, currently compatible with ODBC and OCI two ways to connect to the database!

Source: Internet
Author: User
Tags connect odbc sql return stmt
odbc| Connection Database | The worst thing about PHP is that you've designed a database connection method for each database, which can be compatible with most databases, but when the database needs to change, the big deal is bad!
Here, I would like to introduce a bit of my own experience, hoping to play a good result!
My program code is as follows:
?
function Openconn () {
Open a database connection
Odbc:
$conn =odbc_connect ("DSN", "UID", "pwd");
OCI function
$conn =ocilogon ("chat", "chat");
return $conn;
}
function Opensql ($conn, $sql) {
Execute SQL statement
Odbc
$stmt =odbc_exec ($conn, $sql);
OCI
$stmt =ociparse ($conn, $sql);
Ociexecute ($stmt);
return $stmt;
}
function GetColumn ($stmt, $colname) {
Odbc
$ret =odbc_result ($stmt, $colname);
OCI
$ret =ociresult ($stmt, $colname);
return $ret;
}
function Fecthrow ($stmt) {
Odbc
$ret =odbc_fetch_row ($stmt);
OCI
$ret =ocifetch ($stmt);
return $ret;
}
?>
So, once the database connection changes, we just need to modify this function module!
The code in the actual application is as follows:
?
$conn =openconn ();
$stmt =opensql ($conn, $sql);
Fetchrow ($stmt);
Echo GetColumn ($stmt, "COLUMNNAME");
?>
Welcome everyone to criticize the guidance!

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.