Jump to content

[SOLVED] I'm losing the MySQL Connection (Link)


DataRater

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.

 

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.