|
-
Aug 27th, 2012, 11:40 AM
#1
Thread Starter
Addicted Member
[RESOLVED] PDO connection caching !!!
hi
I have mad my website locally and it works fine, but when I upload it I get this error message:
Fatal error: Call to a member function fetch() on a non-object in /home/rdisast/public_html/class.php on line 63
for debugging, I have changed the password of db connection to a wrong password, but I didn't get "unable to connect" message, the same error appears
is it possible that this is cache or something else?
Last edited by fjober; Aug 27th, 2012 at 11:44 AM.
-
Aug 27th, 2012, 01:47 PM
#2
Re: PDO connection caching !!!
I think, your query might have failed and have returned a FALSE, instead of the resultset. So, you might have been trying to fetch rows from this without checking whether the query have returned a resultset or a FALSE value.
Example:
Code:
$r = $db->query("SELECT something FROM shelf");
if( $r === false )
{
echo 'Sorry, the query failed!';
}
else
{
// fetch rows...
}
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 27th, 2012, 09:17 PM
#3
Thread Starter
Addicted Member
Re: PDO connection caching !!!
thanks for replay akhileshbc
yes, it returns false, but why does it return false while I have tested the sql statement at phpMyAdmin and it works !!!
here is my code :
PHP Code:
<?php class myClass { public $dbh; public function __construct() { $this->dbh = new PDO('mysql:host=localhost;rdisast_db', 'rdisast_user', '$+f~65G@e'); } public function getFieldData($tableName, $fieldNumber, $value, $columnName) { $sth = $this->dbh->query("SELECT * FROM `$tableName` WHERE `$columnName`='$value'"); $fetch = $sth->fetch(); return $fetch[$fieldNumber]; } public function preLang($httpReferer) { $l = ''; $explodedReferer = explode('/',$httpReferer); $c = count($explodedReferer); for ($i = 0; $i < $c; $i++) { if ($explodedReferer[$i] == 'du' || $explodedReferer[$i] == 'en') { $l = $explodedReferer[$i]; break; } } if ($l == '') { $l = $this->getFieldData('settings','dl','1','id'); } return $l; } } $obj = new myClass; if (!$_GET['lang']) { $language = $obj->preLang($_SERVER['HTTP_REFERER']); } else { $language = $_GET['lang']; } if ($language == 'du') { $lKey = 2; } else { $lKey = 1; } $tr = array(); $gT = $obj->dbh->query('SELECT * FROM `translate`'); while($t = $gT->fetch()) { $tr[$t['code']] = $t['word'.$lKey]; }
?>
the first execution of a sql statemnt is in getFieldData() function, and when I debricated it, the error become at the line of while loop "while($t = $gT->fetch()) "
I think the problem in in db connection, but I am sure of the username and password, and permissions for this user
Last edited by fjober; Aug 27th, 2012 at 09:23 PM.
-
Aug 27th, 2012, 10:10 PM
#4
Re: PDO connection caching !!!
try
PHP Code:
print_r($obj->$dbh->errorInfo())
-
Aug 27th, 2012, 10:20 PM
#5
Thread Starter
Addicted Member
Re: PDO connection caching !!!
thank you penagate
oh !!!!
Fatal error: Cannot access empty property in /home/rdisast/public_html/class.php on line 260
-
Aug 27th, 2012, 10:24 PM
#6
Re: PDO connection caching !!!
What's line 260?
Put that code after the query that fails.
For example:
PHP Code:
$sth = $this->dbh->query("SELECT * FROM `$tableName` WHERE `$columnName`='$value'"); if ($sth === null) print_r($this->dbh->errorInfo());
-
Aug 27th, 2012, 10:39 PM
#7
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|