$builder->insert($data); not work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: $builder->insert($data); not work (/showthread.php?tid=77251) |
$builder->insert($data); not work - darkstaring - 08-07-2020 Hi all, I have a problem with a insert in a database. This is the controller: PHP Code: ...... This is model: PHP Code: public function insert_auto($data) The query printed is "SELECT * FROM `veicoli`" instead of "INSERT INTO veicoli ....." Why ? Can you help me ? -------------- Edit: Codeigniter 4.0.4 RE: $builder->insert($data); not work - paulbalandan - 08-07-2020 Because you are using getCompiledSelect. That returns the SELECT query. Try getCompiledInsert instead. RE: $builder->insert($data); not work - darkstaring - 08-18-2020 Thank you! I make a partially fix.. but now I have this error: "message": "Call to undefined method CodeIgniter\\Database\\MySQLi\\Connection::insert()" I think that the error isn't in insert but in the connection: PHP Code: $db = \Config\Database::connect(); RE: $builder->insert($data); not work - jreklund - 08-21-2020 Can't really tell why it's not connecting. Enabled development environment and check the logs. You are however using insert() incorrectly. https://codeigniter.com/user_guide/database/query_builder.html#inserting-data |