I'm coding a website in php but when I tested it, the page indicates HTTP ERROR 500. So I searched for the problem and I found a log file which indicated me the following content:
'ERR_WARNING' in /Applications/MAMP/htdocs/SITE/config/connect.php:3
Stack trace:
#0 /Applications/MAMP/htdocs/SITE/config/functions.php(5): require()
#1 /Applications/MAMP/htdocs/SITE/index.php(4): getArticles()
#2 {main}
thrown in /Applications/MAMP/htdocs/SITE/config/connect.php on line 3
Then I checked the file functions.php but found no errors could you please help me fix this problem.
Here is my functions.php file:
<?php
// ARTICLE FUNCTION
function getArticles()
{
require "./config/connect.php";
$req = $bdd->prepare('SELECT id, title FROM articles ORDER BY id DESC');
$req->execute();
$data = $req->fetchAll(PDO::FETCH_OBJ);
return $data;
$req->closeCursor();
}
?>
Here is my connect.php file:
<?php
$bdd = new PDO('mysql:host=localhost;dbname=blog;charset=utf8','root','root');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERR_WARNING);
?>
Then, I placed the replace command in function.php under the close cursor one, however, it didn't solve the problem
Then, I changed the password in my connect file and in my database so that they are now the same one.
But it didn't solve the problem showing me the following message:
[09-Apr-2019 15:15:31 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: >YES) in /Applications/MAMP/htdocs/SITE/config/connect.php:2
Stack trace:
#0 /Applications/MAMP/htdocs/SITE/config/connect.php(2): PDO->__construct('mysql:host=loca...', 'root', '123')
#1 /Applications/MAMP/htdocs/SITE/config/functions.php(5): require('/Applications/M...')
#2 /Applications/MAMP/htdocs/SITE/index.php(4): getArticles() #3 {main}
thrown in /Applications/MAMP/htdocs/SITE/config/connect.php on line 2
Then, I realised that the password I put in the connect file was wrong and I changed it. It took me back to the first error:
[09-Apr-2019 16:40:18 UTC] PHP Fatal error: Uncaught Error: Undefined class constant 'ERR_WARNING' in /Applications/MAMP/htdocs/SITE/config/connect.php:3
Stack trace:
#0 /Applications/MAMP/htdocs/SITE/config/functions.php(5): require()
#1 /Applications/MAMP/htdocs/SITE/index.php(4): getArticles()
#2 {main}
thrown in /Applications/MAMP/htdocs/SITE/config/connect.php on line 3