Jump to content

Quick Question


Ell20

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/116953-quick-question/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601415
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601424
Share on other sites

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');

Link to comment
https://forums.phpfreaks.com/topic/116953-quick-question/#findComment-601454
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.