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
Post
by Rupo » Thu Jul 05, 2007 11:41 am
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
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Thu Jul 05, 2007 12:46 pm
Would you please describe your problem? What isn't working?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Jul 05, 2007 12:47 pm
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 » Thu Jul 05, 2007 1:09 pm
Hi,
I#ve also tried
Code: Select all
$this->db=mysql_pconnect('localhost', 'foo', 'bar');
with no effect!
shows bool(false);
so long
Rupo
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Jul 05, 2007 1:16 pm
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 » Thu Jul 05, 2007 1:24 pm
arborint wrote:
I am guessing that the real username and password is not 'foo'/'bar'.
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
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Jul 05, 2007 1:51 pm
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 » Thu Jul 05, 2007 1:53 pm
same problem
Rupo
Forum Commoner
Posts: 25 Joined: Thu Jul 05, 2007 11:22 am
Post
by Rupo » Thu Jul 05, 2007 2:03 pm
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 ....
so long
Rupo
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Jul 05, 2007 3:03 pm
Rupo wrote:
I should remove the __ from the constructor ....
That's hilarious.
Where is 'name' being defined?
Rupo
Forum Commoner
Posts: 25 Joined: Thu Jul 05, 2007 11:22 am
Post
by Rupo » Thu Jul 05, 2007 3:07 pm
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);
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Jul 05, 2007 3:16 pm
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 » Thu Jul 05, 2007 3:37 pm
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
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Jul 05, 2007 3:54 pm
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.