Elxis CMS Forum
Support => General => Topic started by: maple on October 28, 2018, 13:42:25
-
Hi,
suddenly when I try to add a new article, Elxis add the ID 0. And when I try to delete this new article, can't do It, also can't publish this article and some other things. I need to go to phpmyadmin and delete manually. And then when I add a new article again, Elxis add ID 0 again. I have about 70 articles that works fine. Don't know why Elxis don't add the following number, example 71 instead of 0.
thanks
-
In phpmyadmin have you modified the auto-incement value for column ID in table elx_content?
PHP My Admin > Click table elx_content > Click tab "Settings" > Set the proper value of "AUTO_INCREMENT" option.
-
Hi thank you,
I just attached an screenshot below. I never modified this.
Could be possible that I need to reinstall MariaDB ? Or some any other issue due a possible server attack?
-
Click tab "Operations" and see the value of the "AUTO_INCREMENT" option.
If you can't fix it by yourself send me with a personal message access details for your site to fix it for you (ftp + phpmyadmin + elxis administration).
-
Hi, I just send you a PM
thanks
-
Problem solved!
The problem was that, for some reason (I don't really know why), the value of auto_increment columns (IN ALL TABLES) did not get the proper value on INSERT statements but, instead, zero. Elxis uses NULL as value on auto increment columns which is automatic updated by mysql. This does not work for you. Maybe the value was not interpreted as NULL but as string or maybe something changed in latest PHP/PDO/MySQL versions although I didn't found something relevant. Maybe was our mistake defining NULL value for auto increment columns. What I did is to remove these columns from INSERT queries in PDO statements. Although I have not seen the problem in other sites I will apply this fix in Elxis official release and in the upcoming Elxis 5.x.
If you have the same problem here is how to fix it:
Open file: includes/libraries/elxis/database/table.class.php
Change line 209 from this:
$data = $this->makeParams();
to this:
$data = $this->makeParams(true);
Change line 587 from this:
private function makeParams() {
to this:
private function makeParams($is_insert=false) {
Add below line 600:
foreach ($this->columns as $name => $column) {
this:
if ($is_insert) {
if ($name == $this->primary_key) {
if ($column['type'] == 'integer') {
$v = (int)$column['value'];
if ($v < 1) { continue; }
}
}
}
One additional change to fix an old bug:
Change lines 622-624 from this:
switch ($column['type']) {
case 'interger':
case 'bit';
To this:
switch ($column['type']) {
case 'integer':
case 'bit':
Save the file and you are ready!
-
Hi datahell, thank you so much!
(I just send you a PM)
-
My original reply updated. Tested and works fine!
-
Great! Thank you so much!!