Content deleted Content added
AvalerionV (talk | contribs) No edit summary |
|||
Line 8:
* the ___location of the data source
* the name of a [[database driver]] which can access the data source
* a [[User identifier
* a user password for data access (if required)
Line 18:
Two kinds of DSN exist:
* '''Machine DSNs'''
* '''File DSNs'''
These are further broken down into
* '''System DSNs'''
* '''User DSNs'''
== Example of use ==
Software (e.g., Crystal Reports, Microsoft Excel, PHP, Perl, Python, Ruby) users can submit CRUD (Create, Read, Update, Delete) queries to a data source by establishing a connection to the DSN.
ASP ([[VBScript]]) code to open a DSN connection might look like the following:
<
Dim DatabaseObject1
Set DatabaseObject1 = Server.CreateObject("ADODB.Connection")
DatabaseObject1.Open("DSN=example;")
</syntaxhighlight>
In [[PHP]] using the PEAR::DB package to open a connection without an external DSN (a "DSN-less connection", i.e., using a Connection String), the code might resemble the following
<
require_once("DB.php");
//$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>";
$dsn = "mysql://john:pass@localhost:3306/my_db";
$db = DB::connect($dsn);
</
PHP with PDO.
<
$dsn = "mysql:host=localhost;dbname=example";
$dbh = new PDO($dsn, $username, $password);
</syntaxhighlight>
In [[Perl]], using the [[
<
my $dsn = "DBI:Pg:database=finance;host=db.example.com;port=$port";
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
Line 60:
my $dbh = DBI->connect($dsn,'username','password');
</syntaxhighlight>
== See also ==
* [[Datasource]]
* [[ADO.NET]]
Line 72:
[[Category:Data access technologies| ]]
{{database-stub}}
|