Run below code in any model file.
$db = $this->getDbo();
$db->setQuery(
"INSERT INTO " . $destination_db->qn('#__categories') .
" (id)" .
" VALUES (0)"
);
try {
$destination_db->execute();
} catch (\RuntimeException $exc) {
echo $exc->getMessage();
}
Create an empty new row in table categories
You get error message:
Field 'description' doesn't have a default value
I attach php Info of my system, even though, that does not seem to be relevant.
phpInfo.pdf
When I run above SQL directly from phpMyAdmin it runs without problems.
As a temporary solution, if you run below:
$db->setQuery("set @@sql_mode = ''");
$db->execute();
before the execution of the insert, then it runs as expected.
If you run :
$db->setQuery('SELECT @@GLOBAL.sql_mode;');
echo "Global: ".$db->loadResult()."<br>";
$db->setQuery('SELECT @@SESSION.sql_mode;');
echo "Session: ".$db->loadResult();
then you get:
Global: NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Session: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
The STRICT_TRANS_TABLES should not be there.
This was problem back in 2010 and is described here: MySQL strict mode incompatibility
Up to Joomla 3.5 no such problem exists, but it reappear in Joomla 4, so something is wrong with MySQLi adapter.
Labels |
Added:
?
|
Category | ⇒ | com_categories SQL |
In 3.8.2 - the mysqli driver sets sql_mode:
// Set sql_mode to non_strict mode
mysqli_query($this->connection, "SET @@SESSION.sql_mode = '';");
and the mysql driver sets sql_mode:
// Set sql_mode to non_strict mode
mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
Status | New | ⇒ | Discussion |
I don't get it. Will this be changed, or we have to manually remove strict mode each time we need to insert an empty row to any table?
The query in the OP should rightfully fail as it's not inserting a valid record into the database. IMO that is not a good example to be basing this issue off of.
IIRC it was a deliberate decision to enable strict mode because of changes in the MySQL platform. I honestly don't remember the full conversation anymore though.
Closed as stated above
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-01-05 21:58:58 |
Closed_By | ⇒ | brianteeman |
In J4:
libraries/vendor/joomla/database/src/Mysqli/MysqliDriver.php
libraries/vendor/joomla/database/src/Mysql/MysqlDriver.php
both set STRICT_TRANS_TABLES
It isn't in J3.8.2