Forums / Bug Reports / [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

[Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

Views: 6,620

Results 21 to 34 of 34
10 Dec 2014, 9:00 PM
#21
tomarriola avatar

tomarriola

Zen Follower

Join Date:
Oct 2004
Posts:
206
Plugin Contributions:
0

[Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

Thanks. My site had been having these errors since 2 months ago when I upgraded. I had no idea until I viewed log files.

If others viewed their log files the premise that thousands use this software without issue would be severely challenged.

Rather, thousands use this software without any idea there is an occasional fatal error issue.

I run test purchases on my site several times a week and I never saw this issue appear until recently during a test-- though my log files show it has been with me since day one.

Tom

10 Dec 2014, 9:30 PM
#22
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

DrByte:

If your site has a damaged cache system, the first step would be to disable the cache so that the error is not triggered ... until such a time as you can resolve whatever is the root cause unique to your specific site.

In /includes/configure.php simply set this to 'none':

define('SQL_CACHE_METHOD', 'none');

A possible fix (as eluded to by mc12345678) could be:
a) /includes/classes/cache.php. Around line 128 you'll see:```
$sql = "insert into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

Change that to:```
$sql = "insert [B]IGNORE [/B]into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',


b) Then turn it back on by setting SQL_CACHE_METHOD back to 'database' temporarily in your /includes/configure.php file.

Then do whatever it is you've been doing to cause the debug logs previously, and confirm whether they continue or not. If they continue, does the error message change? To what?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Dec 2014, 9:47 PM
#23
tomarriola avatar

tomarriola

Zen Follower

Join Date:
Oct 2004
Posts:
206
Plugin Contributions:
0

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

Thanks for the detailed fix. I will make the change and report back.

Tom

10 Dec 2014, 9:52 PM
#24
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

DrByte:

The "fix" in that post deals with sessions, not caching.

Yeah as might have been seen I caught that when trying to both consider the source of the aggravation and look more closely at the initiial problem description and then recalling that on one of the other 1062 threads that the cache was also discussed as a point where this duplication occurs.

Something I'm wondering about with regards to the code changes I suggested, in both cases I ended up following guidance that has been suggested regarding not expecting fields to be in a certain sequence or to only be the fields in the applicable table. The thing is that these two tables seem to be central to operation. By referencing the variables in the way suggested, doesn't that have a potential negative effect/permission? These two tables: cache and sessions I would think should not be modified by other code and therefore the method of assignment originally in the file should be used instead rather than the (field_name1, field_name2, field_name3) values (x, y, z) method proposed?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

10 Dec 2014, 10:08 PM
#25
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

mc12345678:

These two tables: cache and sessions I would think should not be modified by other code and therefore the method of assignment originally in the file should be used instead rather than the (field_name1, field_name2, field_name3) values (x, y, z) method proposed?
The longer-term fix probably warrants properly naming the fields in the query.

I've opened a pull request for review at https://github.com/zencart/zencart/pull/244

But feedback from tomarriola about whether the proposed change is concretely providing relief for his symptoms would be helpful.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

11 Dec 2014, 7:12 AM
#26
tomarriola avatar

tomarriola

Zen Follower

Join Date:
Oct 2004
Posts:
206
Plugin Contributions:
0

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

I applied the file edit and restored the cache in the configure.php file. I got a white screen and a fatal error. The error log was a bit different this time. See below.
Tom

[10-Dec-2014 22:57:37] PHP Fatal error:  1146:Table 'shop10172014a.intodb_cache' doesn't exist :: insert IGNORE intodb_cache set cache_entry_name = 'zc_d6616cb5f4c2cb55d422ea67feb723b0',
                                                 cache_data = 'DATA DELETED',
                   cache_entry_created = '1418281057' ==> (as called by) /var/www/html/www.xxxx.com/xxxx/store/includes/classes/cache.php on line 131 <== in /var/www/html/www.xxxx.com/xxxx/store/includes/classes/db/mysql/query_factory.php on line 155
11 Dec 2014, 9:48 AM
#27
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

tomarriola:

I applied the file edit and restored the cache in the configure.php file. I got a white screen and a fatal error. The error log was a bit different this time. See below.
Tom

[10-Dec-2014 22:57:37] PHP Fatal error: 1146:Table 'shop10172014a.intodb_cache' doesn't exist :: insert IGNORE intodb_cache set cache_entry_name = 'zc_d6616cb5f4c2cb55d422ea67feb723b0',
cache_data = 'DATA DELETED',
cache_entry_created = '1418281057' ==> (as called by) /var/www/html/www.xxxx.com/xxxx/store/includes/classes/cache.php on line 131 <== in /var/www/html/www.xxxx.com/xxxx/store/includes/classes/db/mysql/query_factory.php on line 155


Missing a space after the word into in the first couple of words. Needs to be a space after into and before the next quote.   And try again, if possible. Issue is in the cache file. So close

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

11 Dec 2014, 9:57 AM
#28
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

tomarriola:

I applied the file edit and restored the cache in the configure.php file. I got a white screen and a fatal error. The error log was a bit different this time. See below.
Tom

[10-Dec-2014 22:57:37] PHP Fatal error: 1146:Table 'shop10172014a.intodb_cache' doesn't exist :: insert IGNORE intodb_cache set cache_entry_name = 'zc_d6616cb5f4c2cb55d422ea67feb723b0',
cache_data = 'DATA DELETED',
cache_entry_created = '1418281057' ==> (as called by) /var/www/html/www.xxxx.com/xxxx/store/includes/classes/cache.php on line 131 <== in /var/www/html/www.xxxx.com/xxxx/store/includes/classes/db/mysql/query_factory.php on line 155


There appears to be a small error in the code that DrByte supplied. 

$sql = "insert IGNORE into" . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',


There needs to be a space after the "into" 
Correct code should read

$sql = "insert IGNORE into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',


Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

11 Dec 2014, 10:41 AM
#29
tomarriola avatar

tomarriola

Zen Follower

Join Date:
Oct 2004
Posts:
206
Plugin Contributions:
0

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

The updated fix has been applied. The store works. I'm off to bed. In a few hours I'll check the logs for trouble and report back.
Thanks much
Tom

11 Dec 2014, 11:53 AM
#30
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

mc12345678:

Well, following the little threads related to this issue some more, it looks like the function sql_cache_store is subject to the same potential race condition as identified in that other post. My apologies for not picking up on the difference of code section(s) between the two. The error message originally reported dealt with sql_cache_store, where the suggested fix was in the sessions file of a different function. That said it appears that the same fix could be applied here if it hasn't already.

case 'database':
$result_serialize = $db->prepare_input(base64_encode(serialize($zf_result_array)));
$sql = "insert ignore into " . TABLE_DB_CACHE . " (cache_entry_name, cache_data, cache_entry_created) values
('" . $zp_cache_name . "', '" . $result_seialize . "', '" . time() . "')";
$db->Execute($sql);

$sql = "update " . TABLE_DB_CACHE . " set cache_entry_name = '" .$zp_cache_name . "',
cache_data = '" . $result_seialize . "',
cache_entry_created = '" . time() . "'";
$db->Execute($sql);
return true;
break;

> 
> With the above code to replace the case statement for database entirely (assuming that I typed it 100% correctly.
> 
> Again, sorry for the slight misdirection, though perhaps solved two problems in one thread?! :)

> **DrByte:**
>
> A possible fix (as eluded to by mc12345678) could be:
> a) /includes/classes/cache.php. Around line 128 you'll see:```
$sql = "insert into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

Change that to:```
$sql = "insert [B]IGNORE [/B]into" . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

> 
> b) Then turn it back on by setting SQL_CACHE_METHOD back to 'database' temporarily in your /includes/configure.php file.
> 
> Then do whatever it is you've been doing to cause the debug logs previously, and confirm whether they continue or not. If they continue, does the error message change? To what?

FWIW, above I suggested some code changes for the cache files. I recommend *NOT* implementing these now that I've taken a moment to think. The cache system is designed to provide a temporary relief from looking up the same information multiple times within a short period of time. The changes suggested above (by me) would keep the data resident as long as that data was trying to be cached before expiration.

This is desired for sessions, but not caching and why the alternate code provided above is preferred (though still awaiting result review.)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

11 Dec 2014, 7:30 PM
#31
tomarriola avatar

tomarriola

Zen Follower

Join Date:
Oct 2004
Posts:
206
Plugin Contributions:
0

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

Things now work. Thanks. Here is what I did

1--I edited the line to read

$sql = "insert IGNORE into" . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

2--I changed back my configure file to use database cache.

What I did not do:

I am a bit confused though because there seems to be a second file change from mc12345678 being presented as below. I did not implement it

Tom

case 'database':
$result_serialize = $db->prepare_input(base64_encode(serialize($zf_result_array)));
$sql = "insert ignore into " . TABLE_DB_CACHE . " (cache_entry_name, cache_data, cache_entry_created) values
  ('" . $zp_cache_name . "', '" . $result_seialize . "', '" . time() . "')";
$db->Execute($sql);

$sql = "update " . TABLE_DB_CACHE . " set cache_entry_name = '" .$zp_cache_name . "',
     cache_data = '" . $result_seialize . "',
    cache_entry_created = '" . time() . "'";
$db->Execute($sql);
return true;
break;
11 Dec 2014, 7:38 PM
#32
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

tomarriola:

Things now work. Thanks. Here is what I did

1--I edited the line to read

$sql = "insert IGNORE into" . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

> 
> 2--I changed back my configure file to use database cache.
> 
> What I did not do:
> 
> I am a bit confused though because  there seems to be a second file change from mc12345678 being presented as below. I did not implement it
> 
> Tom
> 
> ```
case 'database':
$result_serialize = $db->prepare_input(base64_encode(serialize($zf_result_array)));
$sql = "insert ignore into " . TABLE_DB_CACHE . " (cache_entry_name, cache_data, cache_entry_created) values
  ('" . $zp_cache_name . "', '" . $result_seialize . "', '" . time() . "')";
$db->Execute($sql);

$sql = "update " . TABLE_DB_CACHE . " set cache_entry_name = '" .$zp_cache_name . "',
     cache_data = '" . $result_seialize . "',
    cache_entry_created = '" . time() . "'";
$db->Execute($sql);
return true;
break;

Disregard that code I posted. (Explained or attempted to be in my latest post). It would delay or possibly prevent cached data from ever being updated. Ie wrong fix for cache related code.

Glad it is fixed. I think I have the same issue on aserver I work with and am going to implement, but didn't use a computer yesterday to do so.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

22 Dec 2014, 7:01 PM
#33
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

tomarriola:

Things now work. Thanks.
@tomarriola
Just following up. How is it now?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Dec 2014, 6:34 PM
#34
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: [Done v1.6.0] What is the answer to PHP Fatal error: 1062:Duplicate entry

DrByte:

Just following up. How is it now?

Since making the change you suggested, I have not had a MyDebug file related to this.

In a somewhat parallel thread, the suggestion to edit sessions.php did not have any effect. ie: 100kb MyDebug files on almost a daily basis.

DrByte:

A possible fix (as eluded to by mc12345678) could be:
a) /includes/classes/cache.php. Around line 128 you'll see:```
$sql = "insert into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

> Change that to:```
$sql = "insert [B]IGNORE [/B]into " . TABLE_DB_CACHE . " set cache_entry_name = '" . $zp_cache_name . "',

Rick
RixStix (dot) com
aka: ChainWeavers (dot) com