Home | Computers & Technology | Programming


Dsn and Dsnless Connection-A brief discussion

By: Manjushree Das

In this article I have discussed two different ways of connecting Microsoft Access database and PHP:

Approach 1

Using DSN (Data Source Name)

What is a DSN?
A DSN(Data source Name) is a logical name that the ODBC(Open database Connectivity) uses to get the drive and other relevant information that are vital for accessing data.

What does a DSN contain?
DSN stores all the information required to connect to your database.
-> Database type
->server / file location
->username and password
-> Connection options

Connection Code


//connect to a DSN "myDSN"

$conn = odbc_connect('myDSN','','');

if ($conn)
{
//the SQL statement that will query the database

//perform the query

//fetch the data from the database
}

//close the connection
}
?>

Advantages:

1)Data source names are easier to remember and hence quite handy to use.
2)When there are lots of data sources to think of and we want a central repository to hold the collection of data sources without having to worry about the actual site and configuration of the data sources.

Disadvantages:

1)When ADO attempts to connect to a database using a System DSN it must perform a lookup in the registry. This lookup slower performance when there are many concurrent connections.
2)With DSN method, you will have to maintain two sets of settings: the script and the DSN itself.
3)ODBC driver for MS Access causes instability on the server.

Approach 2

Without using DSN(DSN-less method)

On the other hand when using DSN-less method we do not have to create a system level DSN for connecting to the database.
All the connection details are included in the connection string in the script itself.

Connection Code


//create an instance of the ADO connection object
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");

//define connection string, specify database driver

$conn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= myDb.mdb";

//Open the connection to the database
{
//declare the SQL statement that will query the database

//execute the SQL statement and return records


//move on to the next record.This is an important step otherwise you may trapped in an endless loop

}

//close the connection and recordset objects

?>

Advantages

1)Often it is difficult to register a DSN and in that scenario its always better to connect to your databases directly.
2)Provides faster database access because it uses native OLE DB providers, while DSN connections make use of ODBC drivers.
3)For portability reasons, it would be better to use DSN-less method

Disadvantages

1)Global database changes require changes be pushed out to all Web site owners inorder to maintain site functionality.
2) Database connection information can be stored in individual PHP files and any changes to it would have to be repeated throughout all the files.

Summary

Some people tend to think that DSN-less is faster while a group of people believe DSN is faster based on several other tests.But if you are using a small site that gets less hits a day then in that case you won't see much difference between the System DSN and DSN-less connection.Both the methods are good as well as bad in their own respective ways.Its upto you to choose the one that suits your requirement.

-By
Manjushree Das.
(www.mindfiresolutions.com)

Article Source: http://www.articlewheel.com

Social Bookmarks:
AddThis Social Bookmark Button Social Bookmarks



  Site Links We Support:
  Home
About Us
Contact Us
RSS Feeds
Privacy Policy
Terms of Service
Link Partners
 
 


**scoop**

physicalworldhyperlink.com | ibusinessplatform.net | concertofolder.com | sonsh.com | envoyence.com | hakerem.org | monarchproject.info | yournjbuilder.com | aliharter.com | bundas.info | healingpoint.info | anthonyrenardoflake.com | alstaley.com | geekgq.com | best365.info | facesandvoices.org | garkomatic.info | musengraving.com | mynetninja.com | naturalhealthperspective.info | site2online.com | wetellitwell.com | wwwtraveldog.com | busby seo challenge

Powered by Article Dashboard