ADOdb: Connection Statement



In this tutorial, we discuss more deep about connection in php adodb. There are 2 connection in adodb: Connect() and PConnect().

Connect($host,[$user],[$password],[$database]) We have used in our practice in adodb introduction. Non-persistent connect to data source or server $host, using userid $user and password $password. If the server supports multiple databases, connect to database $database.

The code like this:

    $db = ADONewConnection($databasetype); 
    $db->debug = true; 
    $db->Connect($server, $user, $password, $database); 

If you are using a Microsoft ADO and not OLEDB, you can set the $database parameter to the OLEDB data provider you are using.

PConnect($host,[$user],[$password],[$database]) Persistent connect to data source or server $host, using userid $user and password $password. If the server supports multiple databases, connect to database $database.

include('adodb.inc.php'); # load code common to ADOdb 
    $conn = &ADONewConnection('access'); # create a connection 
    $conn->PConnect('northwind'); # connect to MS-Access, northwind DSN 

If you confuse pconnect() and connect(), below may be usefull:

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ex, mysql_close() will not close links established by (ex, mysql_pconnect())).



Series this article:
ADOdb: Introduction
ADOdb: Connection Statement
ADOdb: Advance Select Statement
ADOdb: How to show tables
ADOdb: How to show fields
ADOdb: How to show databases
ADOdb: Caching of Recordset
ADOdb: Recordset to HTML
ADOdb: Multi Database Connection
ADOdb: Data Dictionary
ADOdb: Quick Export Data
ADOdb: Insert data style
ADOdb: Replace Data
ADOdb: Log Query
PHP ADOdb: Understanding Pivot Table For Reporting
PHP ADOdb: Creating Pivot Table
PHP ADOdb: Creating Query to Build Pivot Table


Tag: adodb, database, database layer Category: PHP Database Post : October 29th 2007 Read: 8,019 Bookmark and Share

blog comments powered by Disqus