Page 1 of 1
php parse error with mysql function
Posted: Mon Feb 16, 2004 2:00 am
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
Posted: Mon Feb 16, 2004 3:13 am
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");
}
}
Posted: Mon Feb 16, 2004 2:26 pm
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);
Posted: Mon Feb 16, 2004 8:43 pm
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");
?>