Page 1 of 2

Error: Lost Connection

Posted: Thu Jul 05, 2007 11:41 am
by Rupo
Hi,

well I've some problems to get acces to my database.

Using: php5.2 and mysql 5.0

the following script causes the error:

Code: Select all

class DataAccess
    {
    /* $db stores a database resource */
    var $db;

    /* private: $query stores a query resource */
    var $query;

    /* the class constructor */
    public function __construct()
        {
        $this->db=mysql_pconnect(host, user, pass);
        mysql_select_db(name, $this->db) or die(mysql_error());
        }
On php5 all works fine, but ...

I hope someone out here cansolve my problem

Greets
Rupo

Posted: Thu Jul 05, 2007 12:46 pm
by califdon
Would you please describe your problem? What isn't working?

Re: Error: Lost Connection

Posted: Thu Jul 05, 2007 12:47 pm
by Christopher

Code: Select all

$this->db=mysql_pconnect(host, user, pass);
What are host, user, and pass? They are currently shown as constants so that somewhere there should be a:

Code: Select all

define('host', 'localhost');
define('user', 'foo');
define('pass', 'bar');
If they are not supposed to be defines they they should be variables or strings:

Code: Select all

$host = 'localhost';
        $user = 'foo';
        $pass = 'bar';
        $this->db=mysql_pconnect($host, $user, $pass);
// or
        $this->db=mysql_pconnect('localhost', 'foo', 'bar');

Posted: Thu Jul 05, 2007 1:09 pm
by Rupo
Hi,

I#ve also tried

Code: Select all

$this->db=mysql_pconnect('localhost', 'foo', 'bar');
with no effect!

Code: Select all

var_dump($this->db);
shows bool(false);

so long
Rupo

Posted: Thu Jul 05, 2007 1:16 pm
by Christopher
Rupo wrote:

Code: Select all

$this->db=mysql_pconnect('localhost', 'foo', 'bar');
with no effect!
I am guessing that the real username and password is not 'foo'/'bar'. ;) If you use the mysql error message function to get the error, what is the error message?

Posted: Thu Jul 05, 2007 1:24 pm
by Rupo
arborint wrote: I am guessing that the real username and password is not 'foo'/'bar'. ;)
:roll:

Code: Select all

mysql_pconnect() [function.mysql-connect]: Lost connection to MySQL server during query in /var/www/web2/html/lib/DataAccess.php on line 13
Well, know I've tried to connect to another DB. So I catched one from db4free.org. The problems disapear.
But the free one is versioned 5.1 and my one ist 5.0

So I don't really know whats going on, I suggest I#ve to connect the hoster once again

Greetz
Rupo

Posted: Thu Jul 05, 2007 1:51 pm
by superdezign
The connection was... lost? Try using mysql_connect instead of mysql_pconnect.

Posted: Thu Jul 05, 2007 1:53 pm
by Rupo
same problem :?

Posted: Thu Jul 05, 2007 1:55 pm
by superdezign
What is this query on line 13?

Posted: Thu Jul 05, 2007 2:03 pm
by Rupo
line 13

Code: Select all

mysql_select_db(name, $this->db) or die(mysql_error());
To my Opinion, there is nothing wrong.

As I said above, using another db(from db4free.org) .... everthing' s going well!

Earlier this day I send a request to my hoster ... and the reply was in some way funny:
I should remove the __ from the constructor .... :roll: :?:

so long
Rupo

Posted: Thu Jul 05, 2007 3:03 pm
by superdezign
Rupo wrote: I should remove the __ from the constructor .... :roll: :?:
:lol: That's hilarious. :D

Where is 'name' being defined?

Posted: Thu Jul 05, 2007 3:07 pm
by Rupo
In a file named config.php

Code: Select all

//Database
define('host', 'xxx');
define('user', 'xxx');
define('pass', 'xxx');
define('name', 'xxx');

//Site URL + Name
define('SITE_URL', 'xxx');
define('EMAIL_URL', 'xxx');
define('SITE_NAME', 'xxx');
define("key_lifetime", 60*15);

Posted: Thu Jul 05, 2007 3:16 pm
by superdezign
Well, if that's the spot that the error is occurring, maybe you're using an incorrect database name.

Try this instead:

Code: Select all

mysql_query('USE ' . name, $this->db) or die(mysql_error());

Posted: Thu Jul 05, 2007 3:37 pm
by Rupo
no,
error
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /var/www/web2/html/lib/DataAccess.php on line 13

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/web2/html/lib/DataAccess.php on line 14
Lost connection to MySQL server during query

Posted: Thu Jul 05, 2007 3:54 pm
by superdezign
Leave the class alone, create a test script, and try to connect. If you still can't do it, the problem is probably server-side and you'll need to contact your host again.