Ell20 Posted July 28, 2008 Share Posted July 28, 2008 Hi, Im fairly familiar with PHP/MySQL connecting to a database. However I have just downloaded a script and came across this: function db_connect($server = 'localhost', $username = '*****', $password = '*****', $database = '******', $link = 'db_link') { global $$link; Can anyone assist me as to what should go in the "db_link" section? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/ Share on other sites More sharing options...
LemonInflux Posted July 28, 2008 Share Posted July 28, 2008 I googled DB link: A database link is a schema object in one database that enables you to access objects on another database. Not sure how helpful this is, but it's my initial finding, sorry. ---------------- Now playing: Enter Shikari - Today Won't Go Down In History via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601415 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 One would assume it to be a database connection resource as returned by mysql_connect(). Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601417 Share on other sites More sharing options...
ignace Posted July 28, 2008 Share Posted July 28, 2008 your db link is your db connection, probably when passed it uses that one instead of creating a new one Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601418 Share on other sites More sharing options...
Ell20 Posted July 28, 2008 Author Share Posted July 28, 2008 Ok thanks for the answers, but I still dont really understand what I need to put in there? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601419 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 We are really just guessing because one would assume that a function called db_connect() connects to a database. Can we see the actual function? Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601420 Share on other sites More sharing options...
Ell20 Posted July 28, 2008 Author Share Posted July 28, 2008 Here is some more code: //Make the database connection. db_connect() or die('Unable to connect to database server!'); function db_connect($server = 'localhost', $username = '*****', $password = '*****', $database = '****', $link = 'db_link') { global $$link; $$link = mysql_connect($server, $username, $password); if ($$link) mysql_select_db($database); return $$link; } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601424 Share on other sites More sharing options...
LemonInflux Posted July 28, 2008 Share Posted July 28, 2008 oh god, variable variables. Right, $link, I believe, is an existing mysql link. Don't quote me on that though, variable variables screw with my head :/ ---------------- Now playing: Enter Shikari - Return To Energizer via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601428 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 I would change that function. function db_connect($server = 'localhost', $username = '*****', $password = '*****', $database = '****') { if ($link = mysql_connect($server, $username, $password)) { if (mysql_select_db($database)) { return $link; } } return false; } Then to use it.... $conn = db_connect('localhost','yourusername','yourpassword','yourdatabase'); Quote Link to comment https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.