Problem of mysql and php object
Posted: Thu Jun 17, 2004 4:18 pm
How come the code below generates errors? Ignore the watever part, because I'm sure it can connect to my database.
It says:
Thankyou for helping.
Code: Select all
<html>
<title>Connect to database</title>
<body>
<?
class ChatBox{
//variables (attributes)
var $connect;
var $data;
//constructor
function chatbox($host, $user, $password){
mysql_connect($host, $user, $password);
}
//methods (functions)
function open($database){
mysql_select_db($database, $this->connect);
}
function close(){
mysql_close($this->connect);
}
function update(){
$data = mysql_query("select name, message from chatting", $this->connect);
}
function printOut(){
while($row = mysql_fetch_row($this->data))
echo("<b>$rowї0]:</b> $rowї1]<hr>");
}
}
//debugging codes
$box = new chatbox("watever", "watever", "watever");
$box->open("watever");
$box->update();
$box->printOut();
$box->close();
?>
</body>
</html>Code: Select all
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site442/fst/var/www/html/chatbox.php on line 23
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site442/fst/var/www/html/chatbox.php on line 31
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/virtual/site442/fst/var/www/html/chatbox.php on line 35
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site442/fst/var/www/html/chatbox.php on line 27