Jump to content

Recommended Posts

I'm trying to make a connection like this and the code is inside a class

 

require_once('database.php')

 

    $YSLink=DBConnection('database');

 

    if(!is_resource($YSLink)) {

      echo "Failed to connect to the server";

      }

and it tells me it failed

 

 

 

database.php looks like this and is not a class

 

  function DBConnection($database_p)

    {

    $Space = " ";

//-------- Set up Variables -----------------------------------

    $HostName          = 'xxxxx';

    $DatabaseName      = $database_p;

    $UserName          = 'yyyyyyy';

    $Password          = 'zzzzz';

   

  $MySQLLink = @mysqli_connect(  $HostName, $UserName, $Password,$DatabaseName  );

    if( !$MySQLLink )

      {

      Trace(false,"DBConnection: Can't connect to MySQL: ".mysql_error());

      exit();

      }

    else

      {

      Trace(false,"DBConnection: Connection to database made - Whoopee!!!!!!<br />");

      }

  return($MySQLLink);

    }//DBConnection()

and this tells me I've made the connection Whoopee!!!!!!

 

Why didn't the connection get copied over?

 

I've done some investigating and this looks interesting. There is a contradiction. Any idea why?

 

function DBConnection($database_p)

    {

    $Space = " ";

//-------- Set up Variables -----------------------------------

    $HostName          = 'xxxxx';

    $DatabaseName      = $database_p;

    $UserName          = 'yyyyyyy';

    $Password          = 'zzzzz';

 

  $MySQLLink = @mysqli_connect(  $HostName, $UserName, $Password,$DatabaseName  );

 

    if(!is_resource($MySQLLink)) {

      echo "DBConnection()out: Bad Connection";This gets returned

      } else{

      echo "DBConnection()out: Good Connection<br />";

      }

 

 

    if( !$MySQLLink )

      {

      Trace(false,"DBConnection: Can't connect to MySQL: ".mysql_error());

      exit();

      }

    else

      {

      Trace(false,"DBConnection: Connection to database made - Whoopee!!!!!! This gets returned

");

      }

  return($MySQLLink);

    }//DBConnection()

 

I've solved it. As with most nasty problems there was a few things not quite right.

 

is_resource doesn't seem to work with the i function. so mysqli_connect wasn't good.

 

I was using mysql_real_escape_string instead of the i function mysqli_real_escape_string so had my parameters round the wrong way.

 

So solved now.

 

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.