Jump to content
  • 0

successfully added message, but no data inserted in databse


Question

Posted

today we have found that one of our custom plugin have a strange behavior in v4 . after adding a item, the successfully message appear but no data inserted in database !  , when we left some empty fields it return the error validation for that fields; so the validation pass without any issue, after a search in the forum the same behavior was reported in support manager pro in v4 also, no change made in database.

i was thinking what will be the cause for this behavior ?as no error returned from the Record components or the Input components .

i have added the begin() commit() rollback() fucntion to see what happen but no result, also the error_reporting and the debugger is not catching any error !!!

any idea how to diagnostics the problem ?

Recommended Posts

  • 0
Posted
4 hours ago, Blesta Addons said:

i have added the begin() commit() rollback() fucntion to see what happen but no result, also the error_reporting and the debugger is not catching any error !!!

Do you understand how database transactions work? If any SQL statement fails, everything in the transaction fails and the rollback function is called.

4 hours ago, Blesta Addons said:

after some investigation , the $this->Record->lastInsertId(); return 0 .

hope he can come soon :)

That is probably your issue, especially if you are using a transaction. What does your database schema look like? Do you have a primary or foreign key indices that could be causing issues -- a unique index constraint?

Without knowing your custom plugin or a link to a bitbucket or github repo, its hard for anyone to help you out further.

-Adam

  • 0
Posted
22 minutes ago, Adam said:

Do you understand how database transactions work? If any SQL statement fails, everything in the transaction fails and the rollback function is called.

i was firstly thinking about it , and i have removed the transaction, and made a simple query to just test and is returni g a success messages but is not affecting in database

			$data = [];
			$data['category_id'] = '3';
			$data['date_added'] = date('c');
            $this->Record->where('id', '=', $product_id)
                ->update('nh_store_products', $data, ['category_id', 'date_added']);

 

22 minutes ago, Adam said:

That is probably your issue, especially if you are using a transaction. What does your database schema look like? Do you have a primary or foreign key indices that could be causing issues -- a unique index constraint?

Without knowing your custom plugin or a link to a bitbucket or github repo, its hard for anyone to help you out further.

above the table structure . the same structure is working in v 3.2 and above !!!

			$this->Record->
				setField("id", array('type'=>"int", 'size'=>10, 'unsigned'=>true, 'auto_increment'=>true))->				
				setField("company_id", array('type'=>"int", 'size'=>10, 'unsigned'=>true))->
				setField("category_id", array('type'=>"int", 'size'=>10, 'unsigned'=>true))->
				setField("brand_id",  array('type'=>"int", 'size'=>10, 'unsigned'=>true))->
				setField("package_id", array('type'=>"int", 'size'=>10, 'unsigned'=>true))->
				setField("status", array('type'=>"enum", 'size'=>"'active','inactive'", 'default'=>"active"))->
				setField("access", array('type'=>"enum", 'size'=>"'public','private','hidden'", 'default'=>"public"))->
				setField("logo", array('type'=>"varchar", 'size'=>255))->
				setField("allow_comments", array('type'=>"enum", 'size'=>"'enable','disable'", 'default'=>"enable"))->
				setField("promotion", array('type'=>"enum", 'size'=>"'enable','disable'", 'default'=>"disable"))->
				setField("price_type", array('type'=>"enum", 'size'=>"'free','commercial'", 'default'=>"free"))->
				setField("version", array('type'=>"varchar", 'size'=>255))->
				setField("platform", array('type'=>"varchar", 'size'=>255, 'is_null'=>true, 'default'=>null))->
				setField("technology", array('type'=>"varchar", 'size'=>255, 'is_null'=>true, 'default'=>null))->
				setField("credits", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->
				setField("docs", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->
				setField("video", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->
				setField("requirements", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->		
				setField("features_list", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->
				setField("change_log", array('type'=>"mediumtext", 'is_null'=>true, 'default'=>null))->				
				setField("up_votes", array('type'=>"int", 'size'=>10, 'unsigned'=>true, 'default'=>0))->
				setField("down_votes", array('type'=>"int", 'size'=>10, 'unsigned'=>true, 'default'=>0))->
				setField("views", array('type'=>"int", 'size'=>10, 'unsigned'=>true, 'default'=>0))->
				setField("date_added", array('type' => "datetime"))->
				setField("date_updated", array('type' => "datetime", 'is_null'=>true, 'default'=>null))->
				setKey(array("id"), "primary")->
				setKey(array("company_id", "access"), "index")->
				create("nh_store_products", true);

 

  • 0
Posted (edited)
31 minutes ago, Blesta Addons said:

i was firstly thinking about it , and i have removed the transaction, and made a simple query to just test and is returni g a success messages but is not affecting in database


			$data = [];
			$data['category_id'] = '3';
			$data['date_added'] = date('c');
            $this->Record->where('id', '=', $product_id)
                ->update('nh_store_products', $data, ['category_id', 'date_added']);

 

http://source-docs.blesta.com/class-Record.html#_update

Pretty sure you can remove the third parameter on update as $data is a key/value value 

Since update returns a PDOStatement, save the value to a variable and print it out. You should see some more information as to what is going on.

Also, you checked the basics: $product_id is not null? Enable debugging, etc.

$data = [];
$data['category_id'] = '3';
$data['date_added'] = date('c');
$tmp = $this->Record->where('id', '=', $product_id)->update('nh_store_products', $data);
echo "<pre>";
print_r($tmp);
echo "</pre>";

-Adam

Edited by Adam
added reminder to enable debugging
  • 0
Posted
16 minutes ago, Adam said:

 

http://source-docs.blesta.com/class-Record.html#_update

Pretty sure you can remove the third parameter on update as $data is a key/value value 

Since update returns a PDOStatement, save the value to a variable and print it out. You should see some more information as to what is going on.

Also, you checked the basics: $product_id is not null?


$data = [];
$data['category_id'] = '3';
$data['date_added'] = date('c');
$tmp = $this->Record->where('id', '=', $product_id)->update('nh_store_products', $data);
echo "<pre>";
print_r($tmp);
echo "</pre>";

-Adam

Thanks Adam, of course product_id is not null, the output is

changing the same line via phpmyadmin is working . i confirm the same code work in v3.6

PDOStatement Object
(
    [queryString] => UPDATE `nh_store_products` SET `category_id`=?, `date_added`=? WHERE `id`=?
)

 

  • 0
Posted
25 minutes ago, Blesta Addons said:

the equivalent sql code that is working


UPDATE `nh_store_products` SET `category_id` =2, `access` = 'public' WHERE `id` =18

 

 

Good.

 

I think you are already in a transaction and that is why you are seeing this issue.

In my dev system I was able to re-create similar behavior where I started a transaction, ran the update statement and nothing was updated in the database, but http post was fine and directed me back to a new page.

If you try and get another transaction, while in the middle of one, you should NOT be able to get one and get an error.

$data = [];
$data['category_id'] = '3';
$data['date_added'] = date('c');
$ret = $this->Record->begin();
echo "In transaction: $ret True:" . true;
$tmp = $this->Record->where('id', '=', $product_id)->update('nh_store_products', $data);

 

-Adam

 

  • 0
Posted
18 minutes ago, Adam said:

Good.

 

I think you are already in a transaction and that is why you are seeing this issue.

In my dev system I was able to re-create similar behavior where I started a transaction, ran the update statement and nothing was updated in the database, but http post was fine and directed me back to a new page.

If you try and get another transaction, while in the middle of one, you should NOT be able to get one and get an error.


$data = [];
$data['category_id'] = '3';
$data['date_added'] = date('c');
$ret = $this->Record->begin();
echo "In transaction: $ret True:" . true;
$tmp = $this->Record->where('id', '=', $product_id)->update('nh_store_products', $data);

 

-Adam

 

Thanks fro your help .

Finnaly is a blesta BUG, i have searched some blesta files that use equivalent code to my, and i found the support manager . so to reproduce the case do the fallowing

add a new KB article, try to edit it !!!! that all no change has been made with a success message . i hope this should be fixed as soon as possible .

 

  • 0
Posted
18 minutes ago, Blesta Addons said:

Thanks fro your help .

Finnaly is a blesta BUG, i have searched some blesta files that use equivalent code to my, and i found the support manager . so to reproduce the case do the fallowing

add a new KB article, try to edit it !!!! that all no change has been made with a success message . i hope this should be fixed as soon as possible .

 

I did not understand what you wrote. Something is wrong in your environment, not Blesta.

If you login to the demo system on Blesta's system: everything works fine. I was able to add a new KB article, then edit it, and the changes worked.

https://demo.blesta.com/admin/plugin/support_manager/admin_knowledgebase/edit/1/1/

-Adam

  • 0
Posted
14 hours ago, Adam said:

I did not understand what you wrote.

If you login to the demo system on Blesta's system: everything works fine. I was able to add a new KB article, then edit it, and the changes worked.

https://demo.blesta.com/admin/plugin/support_manager/admin_knowledgebase/edit/1/1/

-Adam

if the demo work so is  mysql version maybe ... as is not working at all in my server .

i will try to update the mysql server and see again

  • 0
Posted
14 hours ago, Blesta Addons said:

if the demo work so is  mysql version maybe ... as is not working at all in my server .

i will try to update the mysql server and see again

i have rewrite almost all models and controllers , without success, tested updating mysql server also . hwt i think is something related to my database shema, but why i can't understand why it was working in v3.2/3.6 !

 

  • 0
Posted

i found something very interesting !

when we set date to date('c') it wont add , but when we set date to something like '05/02/2017' it work !!!! as the database schema the dates will set

				setField("date_added", array('type' => "datetime"))->
				setField("date_updated", array('type' => "datetime", 'is_null'=>true, 'default'=>null))->

 

  • 0
Posted

this issue is not affecting one plugin, we have found almost all our plugins are affected by this, even if the support manager pro plugin. ALL the plugins are working in version 3 without any issue, this happen only in v4 FINAL, the same plugins are working in v4 betas !!!

  • 0
Posted

we have found the problem, is the PHP version.

all our test servers with php 5.6 is showing successfull mesage and nothing added to database. all servers that has php 5.5 and less the data well inserted in database .

NOTE; we have not made any change to the files in our test , the same files/code we have tested them in php 5.5 and php 5.6 .

  • 0
Posted
17 minutes ago, Blesta Addons said:

we have found the problem, is the PHP version.

all our test servers with php 5.6 is showing successfull mesage and nothing added to database. all servers that has php 5.5 and less the data well inserted in database .

NOTE; we have not made any change to the files in our test , the same files/code we have tested them in php 5.5 and php 5.6 .

Have you tried PHP 7.0

  • 0
Posted
29 minutes ago, Blesta Addons said:

not tested. we need to recomplie php with ioncube for v7 . when i get time i will try.

have you the announcement plugin? is working for you ?

 

it doesn't mate and we use php 7. So just wondering if you tried it as it could be our end.

  • 0
Posted
1 hour ago, Licensecart said:

it doesn't mate and we use php 7. So just wondering if you tried it as it could be our end.

Tested with php 5.4 and is working also.

so a conclusion is that the plugins won't work in v php5.6 and above .

  • 0
Posted
21 minutes ago, Blesta Addons said:

Tested with php 5.4 and is working also.

so a conclusion is that the plugins won't work in v php5.6 and above .

I wonder if it's something to do with the minimum requirements for PHP 5.6 / 7.0

  • 0
Posted
On 4/3/2017 at 3:56 AM, Blesta Addons said:

i found something very interesting !

when we set date to date('c') it wont add , but when we set date to something like '05/02/2017' it work !!!! as the database schema the dates will set


				setField("date_added", array('type' => "datetime"))->
				setField("date_updated", array('type' => "datetime", 'is_null'=>true, 'default'=>null))->

 

Sounds like you found your problem...

 

What does 

<? echo date('c'); ?>

produce? When you insert that manually via a SQL query from command line or something like phpMyAdmin... does it work? 

Can you also verify that table structure you are using is setup correctly. Are date_added or date_updated DATES, or TIMESTAMPS or DATETIMES, etc.?

 

-Adam

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...