Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.