larry29936 Posted May 4, 2020 Share Posted May 4, 2020 I have the following php code that errors as indicated: $query = $con->query('SELECT FILENAME, country, area, city FROM download WHERE FILENAME is not null'); Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'country' in 'field list' in /home/larry/web/test/public_html/report1.php:47 Stack trace: #0 /home/larry/web/test/public_html/report1.php(47): PDO->query('SELECT FILENAME...') #1 {main} thrown in /home/larry/web/test/public_html/report1.php on line 47 The Select statement doesn't error when run in mysql shell or phpmyadmin. Here's the result of show create table download: localhost/test/download/ http://localhost/phpmyadmin/tbl_sql.php?db=test&table=download&token=5739c407033be3e118287bc7a9041c2c Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Your SQL query has been executed successfully. show create table download download CREATE TABLE `download` ( `ID` int(5) NOT NULL AUTO_INCREMENT, `LOG_TIME` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `IP_ADDRESS` int(64) unsigned NOT NULL, `FILENAME` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `country` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `area` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, `city` varchar(50) COLLATE utf8_general_mysql500_ci DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=1266 DEFAULT CHARSET=utf8 COLLATE=utf8_general_mysql500_ci Does anyone have an idea why this is happening? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted May 4, 2020 Share Posted May 4, 2020 We've been here before. If you remove 'country' does it return the other values? Quote Link to comment Share on other sites More sharing options...
larry29936 Posted May 4, 2020 Author Share Posted May 4, 2020 (edited) same error on column area after removing country. It's like it doesn't like lower case field names. That wasn't it. I changed the area column to upper case, still errors. Edited May 4, 2020 by larry29936 Quote Link to comment Share on other sites More sharing options...
gw1500se Posted May 4, 2020 Share Posted May 4, 2020 Impossible. I would expect the error to be on 'area'. Quote Link to comment Share on other sites More sharing options...
larry29936 Posted May 4, 2020 Author Share Posted May 4, 2020 I wasn't clear, sorry. The error was on column 'area'. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted May 4, 2020 Share Posted May 4, 2020 OK, that is what I figured. You are not accessing the table you think you are. Post the code connecting to the database. 1 Quote Link to comment Share on other sites More sharing options...
larry29936 Posted May 4, 2020 Author Share Posted May 4, 2020 That was the problem. It was connecting to the production db, not the test.db. Thanks for all your help. Quote Link to comment Share on other sites More sharing options...
Phi11W Posted May 7, 2020 Share Posted May 7, 2020 On 5/4/2020 at 2:55 PM, larry29936 said: It was connecting to the production db I think you may have had a "Lucky Escape" here. Your code failed on the "select". It might be that you have a "delete" statement a few lines further down ... If so, you would have been removing "real" Data from your Live database! You need to find a way to prevent this "cross-Environment" connectivity from happening again. Regards, Phill W. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.