How do you query a database which has a variable filename?
I have a sqlite database which i would like to query. However, there is a Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] error thrown when i try to read from a PHP variable.
Following are the codes ($getdb contains the file name of the db):
$final_db 开发者_开发问答= $getdb[2];
$db_test = new PDO ("sqlite:Database/$final_db");
$result_test = $db_test->query("SELECT * from dcerpcrequests limit 2;");
print_r($result_test);
thanks in advance for any help! :)
First, right under the $final_db declaration try with a var_dump($final_db) to see what the contents of the variable exactly are. If they look good, then your problem might be something else such as hidden control characters. Try sanitizing the variable using trim(), this way.
$final_db = trim($getdb[2]);
Your variable is likely to be not what you think it is. it doesn't matter if it's a variable or a hard coded value. the database server doesn't care.
Try var_dump your variables to make sure their value is what you expect it to be.
other than that it should be the working fine.
精彩评论