Can anyone tell me if there is any way to connect to a mysql database in PHP using DSN?? I have a windows hosting account with features of PHP and MYSQL database. Please help me.
//localhost settings replace the username and password of database server add $c_username = "root"; $c_password = ""; $c_database = "db_name"; // Connect. $connection = mysql_connect('localhost', $c_username, $c_password); mysql_select_db($c_database);
Thanks. Let me try this. Actually i work in asp. where the db connection using dsn works like this dim cn // declare variable set cn = server.createobject("adodb.connection") //Declare adodb connection cn.open "dsn=pebdb;" // Declare databse connection where pebdb is databse dsn Code (markup): this info is saved in a file cn.asp which is used wherever connection is required. Should i do the same with the following code. K.i.P.
asp and mysql are not really that compatible to use i dont know if that will work, lemme try to find out...
using dsn isn't necessary, php has the ability to communicate with MySQL processes using php_mysql.dll http://php.net/mysql_connect it's pretty straight forward, if you can asp then you can php with some patience......
No No don't get me wrong. I am not trying to establish dsn connection in asp. I just gave an example to better understand the process in PHP. I want to do mysql connection in PHP using DSN. In asp using DSN helps in making easy connection. Also the code is easier to remember. Thats why i wanted to know if there is a similar process in PHP too. Thanks K.i.P