Page 1 of 1

Problem of mysql and php object

Posted: Thu Jun 17, 2004 4:18 pm
by artfhc
How come the code below generates errors? Ignore the watever part, because I'm sure it can connect to my database.

Code: Select all

<html>
<title>Connect to database</title>
<body>
<?
	class ChatBox&#123;
		//variables (attributes)
		var $connect;
		var $data;
		
		//constructor
		function chatbox($host, $user, $password)&#123;
			mysql_connect($host, $user, $password);
		&#125;
		
		//methods (functions)
		function open($database)&#123;
			mysql_select_db($database, $this->connect);
		&#125;
		
		function close()&#123;
			mysql_close($this->connect);
		&#125;
		
		function update()&#123;
			$data = mysql_query("select name, message from chatting", $this->connect);
		&#125;
		
		function printOut()&#123;
			while($row = mysql_fetch_row($this->data))
				echo("<b>$row&#1111;0]:</b> $row&#1111;1]<hr>");
		&#125;
	&#125;
	
	//debugging codes
	$box = new chatbox("watever", "watever", "watever");
	$box->open("watever");
	$box->update();	
	$box->printOut();		
	$box->close();		
?>

</body>
</html>
It says:

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
Thankyou for helping.

Posted: Thu Jun 17, 2004 4:21 pm
by markl999
Try the suggestions here first:
viewtopic.php?t=17096

Posted: Thu Jun 17, 2004 6:44 pm
by feyd
the object's $connect is never set. the object's $data is never set.