RE: [PHP] Database Error

From: Date: Wed, 06 Mar 2002 21:41:42 +0000
Subject: RE: [PHP] Database Error
Groups: php.general 
Request: Send a blank email to php-general+get-87688@lists.php.net to get a copy of this message
Yes, Jason. I posted it earlier, but here it is again. // Error I'm getting Error in query: SELECT label FROM menu WHERE id = 3 Warning: Supplied argument is not a valid MySQL result resource in e:\localhost\menu\menu.class.php on line 47 // Object being called from get.php <?php require("menu.class.php"); $obj = new Menu(); echo $obj->get_label(1); ?> // Class in the file menu.class.php class Menu { var $hostname; var $user; var $pass; var $db; var $table; function Menu() { $this->set_database_parameters("localhost", "username", "password", "apps", "menu"); } function set_database_parameters($hostname, $user, $password, $db, $table) { $this->hostname = $hostname; $this->user = $user; $this->password = $password; $this->db = $db; $this->table = $table; } function query($query) { $connection = mysql_connect($this->hostname, $this->user, $this->pass) or die ("Cannot connect to database"); $ret = mysql _query($this->db, $query, $connection) or die ("Error in query: $query"); return $ret; } function get_label($id) { $query = "SELECT label FROM $this->table WHERE id = $id"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } }

« previous php.general (#87688) next »