Problem of mysql and php object

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
artfhc
Forum Newbie
Posts: 23
Joined: Sun May 23, 2004 11:38 pm
Contact:

Problem of mysql and php object

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try the suggestions here first:
viewtopic.php?t=17096
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the object's $connect is never set. the object's $data is never set.
Post Reply