PHP MySQL DSN Connections - How to enable mysql://

TheBlackBenzKid picture TheBlackBenzKid · Feb 8, 2012 · Viewed 15.2k times · Source

How do I enable this type of command on a mysql server and what is it?

I see it client code:

//$dsn = "mysql://root@localhost/username";
//$dsn = "mysql://[email protected]/pass";

Normally I would expect:

$con=mysql_connect($db,$dbuSER,$dbpass);

Answer

TheBlackBenzKid picture TheBlackBenzKid · Feb 8, 2012

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:port/my_db";
$db = DB::connect($dsn);

http://en.wikipedia.org/wiki/Data_Source_Name