Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Data source name
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 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: <syntaxhighlight lang="vbscript"> Dim DatabaseObject1 Set DatabaseObject1 = Server.CreateObject("ADODB.Connection") DatabaseObject1.Open("DSN=example;") </syntaxhighlight> In [[PHP]] using the [https://pear.php.net/package/DB/ PEAR::DB] package to open a connection without an external DSN (a "DSN-less connection", i.e., using a Connection String){{Clarify|How is this an example of DSN use|date=June 2013}}, the code might resemble the following: <syntaxhighlight lang="php"> require_once("DB.php"); //$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>"; $dsn = "mysql://john:pass@localhost:3306/my_db"; $db = DB::connect($dsn); </syntaxhighlight> PHP with PDO:<ref>{{cite web |title=PHP: PDO - Manual |url=https://www.php.net/pdo |website=www.php.net |access-date=22 January 2025 |language=en}}</ref> <syntaxhighlight lang="php"> $dsn = "mysql:host=localhost;dbname=example"; $dbh = new PDO($dsn, $username, $password); </syntaxhighlight> In [[Perl]], using the [[Perl DBI]] module, each driver has its own syntax for the DSN attributes. The only requirement that DBI makes is that all the information, except for username and password is supplied in a single string argument. <syntaxhighlight lang="perl"> my $dsn = "DBI:Pg:database=finance;host=db.example.com;port=$port"; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dsn = "DBI:Oracle:host=$host;sid=$sid;port=$port"; $dsn = "DBI:SQLite:dbname=$dbfilename"; my $dbh = DBI->connect($dsn,'username','password'); </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)