php parse error with mysql function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

php parse error with mysql function

Post by nincha »

im building a class and when i try to connect to my sql database i get a parse error, can any one figure it out??

Code: Select all

class Myclass{
var $dbh;

$this->dbh=mysql_connect ("localhost", "acount", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

}
im quite sure its this thats casueing the error because when i comment them out, the error goes away. thnx
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

class Myclass{
var $dbh;

$this->dbh=mysql_connect ("localhost", "acount", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

}
Yeah, that's invalid syntax for a class. Needs to be something like

Code: Select all

class Myclass{ 
    var $dbh; 

    function DBConnect(){
        $this->dbh=mysql_connect ("localhost", "acount", "password") or die ('I cannot connect to the database because: ' . mysql_error()); 
        mysql_select_db ("database"); 
    }

}
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

hey, i got the connection to establish i think, but when i try to querry a table, i dosnt work...

Code: Select all

$result = mysql_query("SELECT * FROM table",$this->dbh);
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
$result = mysql_query("SELECT * FROM table",$this->dbh);
?>
should be

Code: Select all

<?php
$result = mysql_query("SELECT * FROM table,$this->dbh");
?>
Post Reply