473,466 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DSN vs explicit connection

I'm new in the PHP/MySQL arena - -
which is more common - to use DSNs or to implicitly code the connection
strings in the pages?
Aug 24 '05 #1
1 1440
Elmo Watson (sp**********@No.Spam.Hotmail.com) wrote:
: I'm new in the PHP/MySQL arena - -
: which is more common - to use DSNs or to implicitly code the connection
: strings in the pages?

DSNs?

I use a small php script called Database.php that creates a global
variable $dbh and makes sure the correct database is selected. That
script is stored outside of the web tree, and usually has the login
details hardcoded, though it can read them from a config if needed. The
script is very small so I treat the entire things as part of the
configuration data. Also, it doesn't set any variables except the handle,
so a script that uses the database script can not accidently use the login
variables and expose them.

Each main php script can then simply say

include_once("Database.php");

and afterwards it can use "$dbh" in database calls. I find that method
most convenient.

Many people store the username, password, and other connect information in
a seperate file which they require and then use within their main
script.

include_once("LoginDetails.php"); # OR
include_once("AppConfigDetails.php");

$dbh=mysql_pconnect($host,$user,$pass) or die "naughty database";
# etc.

Either way, I wouldn't recommend putting the connection details in the
body of the main script. At the very least, seperating them makes it
easier to have multiple copies of the script that access different
databases, for testing etc.

--

This programmer available for rent.
Aug 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: biro man | last post by:
I have a dynamic database driven page that I have been working on and tweaking etc until I have got it to work pretty much the way I want it to. I also have a defined website. I wish to include...
2
by: Dario | last post by:
Trying to compile the following code-fragment with g++ 2.96: class Entity { private: void * data; public: explicit Entity(int); explicit Entity(Entity &); virtual ~Entity(); void...
1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
9
by: Tanmoy Bhattacharya | last post by:
Hi, This is a question about whether I am right that a particular syntactic sugar is missing in C++. Let me explain with an example. Let us say I have a class for complex numbers, and I want...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
3
by: Jja | last post by:
Hello, I am very new to this site. before i start may i first introduce myself i am 'Jhalil, a beginner Vb6 programmer. i stumbled on this site on my quest for a code in vb that can connect me...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.