I have just started working on PHP and I am currently working on a simfony project. I have a query that inserts correctly a row in a table and then I need to retrieve the id of that row and use it to insert other values in another table. The problem is that I do not know how pass dynamic values in a sql query in php.
This is the query I wrote and the value in gridConfigId must be dynamic butof course just by passing it as $recordId is not working.
$recordId = $this->addSql('SELECT id FROM gridconfigs ORDER BY creationDate DESC LIMIT 1');
$this->addSql(" INSERT INTO `gridconfig_favourites` (`ownerId`, `classId`, `objectId`, `gridConfigId`, `searchType`, `type`) VALUES
(12, 'EF_OSO', 0, $recordId, 'folder', 'object'),
(12, 'EF_OSO', 624, $recordId, 'folder', 'object');");
What is the right syntax?
尝试使用:
$recordId = $this->connection->fetchColumn('SELECT id FROM gridconfigs ORDER BY creationDate DESC LIMIT 1');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.