0
When I try to execute the SELECT
server accuses this msg: Fatal error: Call to a member function prepare() on a non-object in blog.php on line 97
the line referred to is:
$readPost = $db->prepare($postagemRead);
a little more like this so:
$pg = 1;
$limite = 5;
$inicio = ($pg * $limite) - $limite;
$postagemRead = "SELECT * FROM postagem ORDER BY datapost DESC LIMIT :inicio,:limite";
try{
$readPost = $db->prepare($postagemRead);
the connection file is this:
<?php
try{
$db = new PDO("mysql:dbname=database;host=localhost;charset=utf8;","root","");
}catch(PDOException $e){
$e -> getMessage();
}
?>
do not see the problem seen running this on the local server(wamp server) and runs normal, but on the host of that error what may be?
Error:
Exception 'Pdoexception' with message 'SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)' in /home/vhosts/molbe.freetzi.com/config.php:3 Stack trace: #0 /home/vhosts/molbe.freetzi.com/config.php(3): PDO->__Construct('mysql:dbname=85...', 'root', ') #1 /home/vhosts/molbe.freetzi.com/padrao.php(1): require_once('/home/vhosts/mo...') #2 {main}' in /home/vhosts/molbe.freetzi.com/config.php:5 Stack trace: #0 /home/vhosts/molbe.freetzi.com/padrao.php(1): require_once() #1 {main} thrown in /home/vhosts/molbe.freetzi.com/config.php on line 5
The line
$e->getMessage()
does absolutely nothing within thatcatch
. You need to put an echo/die or do some treatment oncatch
, otherwise the code will continue running normally even if there is some error in the connection.– André Ribeiro
Error 'Exception 'Pdoexception' with message 'SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)' in /home/vhosts/molbe.freetzi.com/config.php:3 Stack trace: #0 /home/vhosts/molbe.freetzi.com/config.php(3): PDO->_Construct('mysql:dbname=85...', 'root', ') #1 /home/vhosts/molbe.freetzi.com/padrao.php(1): require_once('/home/vhosts/mo...') #2 {main}' in /home/vhosts/molbe.freetzi.com/config.php:5 Stack trace: #0 /home/vhosts/molbe.freetzi.com/padrao.php(1): require_once() #1 {main} thrown in /home/vhosts/molbe.freetzi.com/config.php on line 5
– Hebert Lima