Error: Lost Connection

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Error: Lost Connection

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Would you please describe your problem? What isn't working?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Error: Lost Connection

Post 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');
(#10850)
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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?
(#10850)
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The connection was... lost? Try using mysql_connect instead of mysql_pconnect.
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post by Rupo »

same problem :?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What is this query on line 13?
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Rupo wrote: I should remove the __ from the constructor .... :roll: :?:
:lol: That's hilarious. :D

Where is 'name' being defined?
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post 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);
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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());
Rupo
Forum Commoner
Posts: 25
Joined: Thu Jul 05, 2007 11:22 am

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
Post Reply