Debugging SQL PHP

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
hhawkins
Forum Newbie
Posts: 2
Joined: Fri Nov 02, 2007 8:16 am

Debugging SQL PHP

Post by hhawkins »

I am taking over code and a website from a past developer and am still getting my feet wet as far as this advanced of PHP code.I am getting an error when the code attempts to display an error message to users.
ERROR:
Fatal error: Call to a member function query() on a non-object in .../inc_sql.php on line 27

I have searched and searched and have not been able to fuigure this out I appreciate any help.

Code: Select all

<?PHP
//global $dbc; 
$dbc = new DBI;
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) exit('This file can not be accessed directly...');

class DBI
{
public $dbconn, $nfreed;
private $result, $threads;
  function __construct()
  {
  if(basename($_SERVER['SCRIPT_NAME'])=="message.php" && $_GET['error']) return "";
  $this->nfreed=false;
   $sqlhost = "IP";
   //$sqlhost = "localhost";
   @$this->dbconn = new mysqli($sqlhost, "USER", "PASS", "DATABASE");


   if(mysqli_connect_errno()) header("Location: message.php?error=sqlserver"); 
   //die("Critical Error: ".mysqli_connect_error()); 
  }

  function query($sql, $flag = MYSQLI_STORE_RESULT)
  {
  //echo("<p>".$sql."</p>");
  if($this->nfreed) {$this->free();}
  [b] if(!$this->result = $this->dbconn->query($sql)) header("Location: message.php?error=sqlcmd&errno=".$this->dbconn->errno);[/b]
   //die("<pre>Mysql Error: ".$this->dbconn->error."</pre>");
   $this->nfreed=true;
   return $result;
  }
  function get_threads() {
  global $threads;
  if($threads==""){
  ereg ("Threads: (...)", $this->dbconn->stat(), $regs);
  $threads = trim($regs[1]);
  }
  return $threads; 
  }

Any help is greatly appreciated!
User avatar
seppo0010
Forum Commoner
Posts: 47
Joined: Wed Oct 24, 2007 4:13 pm
Location: Buenos Aires, Argentina

Post by seppo0010 »

What it is telling you is that dbconn property is not an object.
dbconn is created on the class constructor
@$this->dbconn = new mysqli($sqlhost, "USER", "PASS", "DATABASE");
Try removing the @ to see if there is an error on that object creation
hhawkins
Forum Newbie
Posts: 2
Joined: Fri Nov 02, 2007 8:16 am

Post by hhawkins »

I did try that as well as uncommenting the die commands.
But the same error comes up.

What is the use of the ! before the "if(!$this->result " doesn't that mean not?
Post Reply