Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 09:40 AM
Martin Slingsby
Guest
 
Posts: n/a
Default can't see the error (PHP5)

Anyone who can decipher this error message? What is PHP trying to tell me?

exception 'MysqlException'
in /var/www/localhost/htdocs/phenixsp/include/DB.inc:72 Stack trace:
#0 /var/www/localhost/htdocs/phenixsp/include/DB.inc(58):
DB_MysqlStatement->__construct(NULL, 'SELECT * FROM u...')
#1 /var/www/localhost/htdocs/phenixsp/login.php(21):
DB_Mysql->prepare('SELECT * FROM u...') #2 {main}

The code is:
// login.php
<?php

// DB.inc handles all database connectivity and queries
include('include/DB.inc');
include('include/Conf.inc');

// rename variables to simplify further code
$user = $_GET['usr'];
$pass = $_GET['pass'];

// catch early error on part of the user
// you can't leave either or both variable empty in the login process

if(isset($user) && isset($pass)){

// do something to check credentials

$dbh = new DB_Mysql('$DBUSER', '$DBPASS', '$HOST', '$DB');
$newquery = "SELECT * FROM users WHERE name = :1";
try{
$stmt = $dbh->prepare($newquery); //line 21
$stmt->execute($user);

}
catch (MysqlException $e) {
print $e;

}

//DB.inc - starting on line 54

public function prepare($query){
if(!$this-dbh){
$this->connect();
}
return new DB_MysqlStatement($this->dbh, $query);
}
}

class DB_MysqlStatement {
protected $result;
protected $binds;
public $query;
public $dbh;

public function __construct($dbh, $query){
$this->query = $query;
$this->dbh = $dbh;
if(!is_resource($dbh)){
throw new MysqlException("Not a valid database connection");
}
}
}
  #2  
Old July 17th, 2005, 09:40 AM
Andy Hassall
Guest
 
Posts: n/a
Default Re: can't see the error (PHP5)

On Sat, 18 Sep 2004 14:20:26 GMT, Martin Slingsby <Keizer.S@gmail.com> wrote:
[color=blue]
>Anyone who can decipher this error message? What is PHP trying to tell me?
>
>exception 'MysqlException'
>in /var/www/localhost/htdocs/phenixsp/include/DB.inc:72 Stack trace:
>#0 /var/www/localhost/htdocs/phenixsp/include/DB.inc(58):
>DB_MysqlStatement->__construct(NULL, 'SELECT * FROM u...')[/color]

Here's the big clue, the NULL.
[color=blue]
>#1 /var/www/localhost/htdocs/phenixsp/login.php(21):
>DB_Mysql->prepare('SELECT * FROM u...') #2 {main}
>
> $dbh = new DB_Mysql('$DBUSER', '$DBPASS', '$HOST', '$DB');[/color]

Single quotes? It's unlikely the database host is the literal string $HOST,
etc.

So this probably failed, but you didn't catch any exceptions or check for
errors. Regardless, you carry on:
[color=blue]
> $newquery = "SELECT * FROM users WHERE name = :1";
> try{
> $stmt = $dbh->prepare($newquery); //line 21[/color]

$dbh is at best in some sort of invalid, disconnected state so this will fail.
[color=blue]
>class DB_MysqlStatement {
> protected $result;
> protected $binds;
> public $query;
> public $dbh;
>
> public function __construct($dbh, $query){[/color]

The backtrace said the first parameter, $dbh, was NULL.
[color=blue]
> $this->query = $query;
> $this->dbh = $dbh;
> if(!is_resource($dbh)){[/color]

NULL is not a resource so:
[color=blue]
> throw new MysqlException("Not a valid database connection");[/color]

You get an exception thrown.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles