SQLSTATE[HY000] [2002] No such file or directory

My website URL is: http://abmsolucoes.cf/

**What I’m seeing is:**SQLSTATE[HY000] [2002] No such file or directory

Erro de conexão com banco de dados: SQLSTATE[HY000] [2002] No such file or directory
Fatal error : Uncaught Error: Call to a member function query() on null in /home/vol6_8/epizy.com/epiz_24477343/htdocs/models/Professor.php:105 Stack trace: #0 /home/vol6_8/epizy.com/epiz_24477343/htdocs/controllers/homeController.php(13): Professor->totalProf() #1 /home/vol6_8/epizy.com/epiz_24477343/htdocs/core/Core.php(43): homeController->index() #2 /home/vol6_8/epizy.com/epiz_24477343/htdocs/index.php(22): Core->run() #3 {main} thrown in /home/vol6_8/epizy.com/epiz_24477343/htdocs/models/Professor.php on line 105

Files config to database:

<?php require 'environment.php'; $config = array(); if(ENVIROMENT == 'development'){ define("BASE_URL","http://abmsolucoes.cf/"); $config['dbname'] = 'epiz_24477343_dbacademia'; $config['host']='sql213.epizy.com'; $config['dbuser'] = 'epiz_24477343'; $config['dbpass'] = 'Password'; }else{ define("BASE_URL","http://abmsolucoes.cf/"); $config['dbname'] = 'epiz_24477343_dbacademia'; $config['host']='sql213.epizy.com'; $config['dbuser'] = 'epiz_24477343'; $config['dbpass'] = 'Password'; } global $db; try{ $db = new PDO("mysql:dbname=".$config['dbname'].";host".$config['host'],$config['dbuser'],$config['dbpass']); }catch(PDOException $e){ echo "Erro de conexão com banco de dados: ".$e->getMessage(); } ?>

I am sorry I did not properly read your problem earlier before replying.

Could you please tell me what framework you are using?

2 Likes

Thank you Niekon for answering,
I am using MVC, I have a database connection configuration file using PDO and I call this file on my other pages, but where there is a request to the bank, I present an error like the one I posted.

I am seeing this error. Could you please fix this first.

1 Like

Niekon, thanks again for the return.
Now it looks like it worked, but now it’s showing error 500.
My .htaccess file is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /http://abmsolucoes.cf/index.php?url=$1 [QSA,L]

is it anyway?

And my index.php is:

<?php session_start(); require 'config.php'; spl_autoload_register(function($class){ if(file_exists('controllers/'.$class.'.php')){ require 'controllers/'.$class.'.php'; }else if(file_exists('models/'.$class.'.php')){ require 'models/'.$class.'.php'; }else if(file_exists('core/'.$class.'.php')){ require 'core/'.$class.'.php'; }else{ header("Location: ".BASE_URL); } }); $c = new Core(); $c->run(); ?>

On your .htaccess I can see a / before your website URL. Remove that.

1 Like

If what @Ergastolator1 said above does not work, try changing this line to simply:

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

2 Likes

Thanks so much Ergastolator1 worked out.

2 Likes

Thank you so much Niekon for your help it worked out.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.