I just tried that Robert. It still gives me the same error that it did
before. There is no error after the mysql_connect. It definitely is
connecting. If it didn't connect then it wouldn't pass the query to the
database in the first place and spit out an error on the SQL syntax. I
checked the syntax on the MySQL command line and it worked just fine. So
it's not the syntax either. I don't know what it could be  :(



-----Original Message-----
From: Robert V. Zwink [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, March 07, 2002 3:42 PM
To: Navid Yar
Subject: RE: [PHP] Database Error



Could you try changing your query() method to

function query($query) {
  $connection = mysql_connect($this->hostname, $this->user,
$this->pass) or die ("Cannot connect to database");

echo mysql_error();  // put this here

  $ret = mysql _query($this->db, $query, $connection) or die ("Error in
query: $query");
  return $ret;
}

I think echoing out the mysql_error() will help pinpoint the problem.
Seems like it is unable to connect?

Robert Zwink
http://www.zwink.net/daid.php




-----Original Message-----
From: Navid Yar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 06, 2002 4:42 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Database Error




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];
   }
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to