0

I'm having a weird situation here.

I'm trying create a PDO object, like this:

$dbh = new PDO('mysql:host='.$hostname.';dbname='.$dbname,$username, $password);

I have rewriting ON in my .htaccess file. when I try to run the script using a URL that will trigger a rewrite rule, it shows me the following error:

Fatal error: Class 'PDO' not found

I have a exception rewrite rule for a directory where the script is, named PHP, like this:

RewriteRule ^(php)($|/) - [L]

if I run the scripting directly from the directory, it runs normally with no erros.

I don't know why this is happening. any clues?

Thank you

2
Contributors
11
Replies
36
Views
3 Years
Discussion Span
Last Post by Tpojka
0

yes, because I can create the PDO object when I don't use the rewrite rule
here is the rewrited url -> www.qualocep.com/estados/
and here is the actual script -> www.qualocep.com/php/lista_estado.php
The error occurs only when I try to access the file via the rewrited url.

0

Is it solved, because both links give same result, array of JSON formated objects/arrays?

0

Sorry.
Try this:
www.qualocep.com/dbc/
and this
www.qualocep.com/php/dbc.php

0

this is the dbc.php code

global $dbh;
try{
    $dbh = new PDO('mysql:host='.$hostname.';dbname='.$dbname,$username, $password);
    echo "OK";
}catch (Exception $e){
    die("Erro ao tentar conectar ao banco de dados");
}
0

I think you should write rewrite condition in your htacces file that is used in particular rule.
I wouldn't know right now without reading the code.
But I would suggest you protection of folder with IndexIgnore * or something similar.

Not sure but try this:

RewriteCond $1 ^(/php/)
RewriteRule ^(.*)$ $1.php [L]

Edited by Tpojka

0

did it as you said, but the exception for the php directory stopped working, and had no effect in the PDO load

0

Solve it.

There was an empty php.ini in the public_html, I deleted it, and it worked.

thank u all

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.