By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,722 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,722 IT Pros & Developers. It's quick & easy.

can't see the error (PHP5)

P: n/a
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");
}
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 18 Sep 2004 14:20:26 GMT, Martin Slingsby <Ke******@gmail.com> wrote:
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...')
Here's the big clue, the NULL.
#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');
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:
$newquery = "SELECT * FROM users WHERE name = :1";
try{
$stmt = $dbh->prepare($newquery); //line 21
$dbh is at best in some sort of invalid, disconnected state so this will fail.
class DB_MysqlStatement {
protected $result;
protected $binds;
public $query;
public $dbh;

public function __construct($dbh, $query){
The backtrace said the first parameter, $dbh, was NULL.
$this->query = $query;
$this->dbh = $dbh;
if(!is_resource($dbh)){
NULL is not a resource so:
throw new MysqlException("Not a valid database connection");


You get an exception thrown.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.