php mysql database connection in an array with port number -


in php doing connection mysql database in simple way this

<?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) {     die('could not connect: ' . mysql_error()); } echo 'connected successfully'; mysql_close($link); ?> 

but want more professional way of database connection in array(where variable in array) can use variable mysql port number within that. can kindly tell me how this? , suggestions appreciable. thanks..

for more professional, start worrying switching pdo. there tons of tutorials on it. same sql, different way of working it.

beyond doesn't matter if it's array or separate variable if you're using globals procedural programming fine when needed.

my main advice whenever need use db, use single configuration file include gather these variables, b/c many times when clean sites later have go hunting through 50 different files update connection strings.

$dbconfig = array(     'user' => 'dbusername',     'pass' => 'dbpassword',     'host' => 'dbhostaddr',     'name' => 'dbhostname', ); $link = mysql_connect($dbconfig['host'], $dbconfig['user'], $dbconfig['pass']);   // later you'd use mysql_select($dbconfig['name']); 

edit: sigh forget $'s


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -