Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '*' in 'field list' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '*' in 'field list'

I am attempting to insert a record to MySQL using PDO, my sql statement can be seen in the following code. https://code.sololearn.com/wA15A15A242a When this code is executed i am met with the following error message; Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '*' in 'field list' in C:\xampp\htdocs\inven\app\Crud.php:27 Stack trace: #0 C:\xampp\htdocs\inven\app\Crud.php(27): PDOStatement->execute(Array) #1 [internal function]: Crud->{closure}(Object(ClanCats\Hydrahon\Query\Sql\Select), 'select *, mon...', Array) #2 C:\xampp\htdocs\inven\vendor\clancats\hydrahon\src\Builder.php(149): call_user_func_array(Object(Closure), Array) #3 [internal function]: ClanCats\Hydrahon\Builder->executeQuery(Object(ClanCats\Hydrahon\Query\Sql\Select)) #4 C:\xampp\htdocs\inven\vendor\clancats\hydrahon\src\BaseQuery.php(214): call_user_func_array(Array, Array) #5 C:\xampp\htdocs\inven\vendor\clancats\hydrahon\src\Query\Sql\Select.php(477): ClanCats\Hydrahon\BaseQuery->executeResultFetcher() #6 C:\xampp\htdocs\inven\app\Controller.php(212): ClanCats\Hydrahon\Query\Sql\Select->get() #7 C:\xampp\htdocs\inven\app\Controller.php(19): Controller->Inventaris() #8 C:\xampp\htdocs\inven\index.php(23): Controller->__ in C:\xampp\htdocs\inven\app\Crud.php on line 27 This is no doubt a simple solution to this problem but i cannot seem to see it, can anyone point me in the right direction?

30th Apr 2021, 3:07 PM
Adam Fakhrul Rozi
Adam Fakhrul Rozi - avatar
3 Answers
+ 2
Hi Adam, Your code and problem description are really cryptic + you only show a part of the code: you should really use more obvious variable and function names and comment your code. But from what I see, the error comes from your SELECT statement (that I guess gets the column names used in the Insert we don't see) on line 68. I would replace line 68: $tes = $this->raw("SELECT * FROM information_schema.columns where TABLE_NAME='$tb' and table_schema='$this->dbname'")->result; ...With the following 2 lines...
27th May 2021, 5:30 PM
Tom BWDEV 🇺🇦
Tom BWDEV 🇺🇦 - avatar
+ 2
$sql = "SELECT * FROM information_schema.columns where TABLE_NAME=' " . $tb . " ' and table_schema=' " . $this->dbname . " ' "; $tes = $this->raw($sql)->result; It should allow PHP to evaluate your $tb and $this->dbname variables in the select statement. Single quotes aren't evaluated otherwise. Let me know if that fixes your error as I can't test it myself.
27th May 2021, 6:02 PM
Tom BWDEV 🇺🇦
Tom BWDEV 🇺🇦 - avatar
+ 2
You may remove some extra spaces I added to avoid a bug from the messaging part of the app... Good luck 🙂
27th May 2021, 6:04 PM
Tom BWDEV 🇺🇦
Tom BWDEV 🇺🇦 - avatar