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

Recommended Answers

Is enabled dll extension in your php.ini file?
Can you check that?

Jump to Post

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

Jump to Post

What do you want to do with this line?
RewriteRule ^(php)($|/) - [L]

Jump to Post

All 11 Replies

Is enabled dll extension in your php.ini file?
Can you check that?

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.

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

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

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");
}

What do you want to do with this line?
RewriteRule ^(php)($|/) - [L]

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]

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

Solve it.

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

thank u all

Glad you made it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.