Calltoamemberfunctionfetch () onanon-object error try {$ dsn = & quot; mysql: host = localhost; dbname = db_upan & quot; $ db = newPDO ($ dsn, call to a member function fetch () on a non-object error
Try {
$ Dsn = "mysql: host = localhost; dbname = db_upan ";
$ Db = new PDO ($ dsn, "root ","");
$ SQL = "select * form tb_uptype ";
$ Statement = $ db-> query ($ SQL );
While ($ result = $ statement-> fetch (PDO: FETCH_ASSOC )){
Echo $ result ['genrename'];
}
$ Db = null;
} Catch (PDOException $ e ){
Echo "error. ";
}
Code above: the error Fatal error: Call to a member function fetch () on a non-object in C: \ xampp \ htdocs \ upan \ test is prompted during running. php on line 7;
What is the reason? Wait...
------ Solution --------------------
$ SQL = "select * from tb_uptype ";
------ Solution --------------------
$ SQL = "select * form tb_uptype ";
Should be
$ SQL = "select * from tb_uptype ";
The SQL command is wrong. Naturally, subsequent code also has errors.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service