http://drupal.org/node/1213730

Just done some very rudimentary diagnosis and this module appears to be causing this error for ubercart dev.

Once disabled the error stops occuring

thx,
Ken

Comments

mattcasey’s picture

Priority: Normal » Major

For other people, I had the same problem but got this error: mysqli_real_escape_string() expects parameter 2 to be string, array given in database.mysqli.inc on line 330. It occurs when clicking "Review order" and you can see in the uc_order table that the $order variable does not get saved.

This should be a critical error, we had some anonymous checkouts without their orders being saved, and some recurring fees failed to renew.

Medom’s picture

I have the same error. An update would be cool.

emmajane’s picture

Priority: Major » Critical
dsobon’s picture

Fix for "mysqli_real_escape_string() expects parameter 2 to be string, array given in db_escape_string()":

--- uc_mailchimp.module.orig 2009-12-17 01:00:00.000000000 +1100
+++ uc_mailchimp.module 2011-08-17 13:58:03.000000000 +1000
@@ -118,7 +118,7 @@
         return $review;
     break;
     case 'process':
-        $arg1->uc_mailchimp = $arg2;
+        $arg1->uc_mailchimp = serialize($arg2);
       
     break;
     case 'settings':
merzikain’s picture

Still having the error with MySQL.

jim kirkpatrick’s picture

Status: Active » Reviewed & tested by the community

#5 seems to have fixed it for us...

JayKayAu’s picture

#5 fixed it for us as well.

If this is acceptable, can we please have this patch committed?

Thanks in advance :)

tea.time’s picture

I ran into this same bug the other day. It busted a client's Ubercart system because none of the user's info got saved with their order.

I believe the fix actually needs two parts.

First is as above:

case 'process':
  $arg1->uc_mailchimp = serialize($arg2);

Second part is that now that the value is being serialized earlier (at the process stage), then once it actually gets saved, we don't want to serialize it again. I suggest adjusting uc_mailchimp_order() (line 76) as:

function uc_mailchimp_order($op, &$arg1) {
  switch ($op) {
    case 'save' :
        $sql = "UPDATE {uc_orders} SET uc_mailchimp = '%s' WHERE order_id = %d";
        if(is_array($arg1->uc_mailchimp)){
            db_query($sql, serialize($arg1->uc_mailchimp),$arg1->order_id);
        }
        else {
            db_query($sql, $arg1->uc_mailchimp, $arg1->order_id);
        }
    break;
    
    case 'load' :
        $arg1->uc_mailchimp = unserialize($arg1->uc_mailchimp);
    break;
  }
    
}

(The if/else check protects against having to change this part again in the future if the point of serialization happens to change again elsewhere.)

dlcerva’s picture

A slightly cleaner approach that I haven't gotten around to testing yet is the following:

<?php
function uc_mailchimp_order($op, &$arg1) {
  switch ($op) {
    case 'presave' :
      if(is_array($arg1->uc_mailchimp)) {
        $arg1->uc_mailchimp = serialize($arg1->uc_mailchimp);
      }
      break;
    case 'load' :
      $arg1->uc_mailchimp = unserialize($arg1->uc_mailchimp);
      break;
  }
}
?>

This should eliminate the need to serialize twice as well as remove the unnecessary database calls.

fattshin’s picture

I think the cleaner way of fixing this issue is adding 'serialize' => TRUE to uc_mailchimp_schema_alter.

function uc_mailchimp_schema_alter(&$schema) {
    $schema['uc_orders']['fields']['uc_mailchimp'] = array(
        'description' => t('The uc_mailchimp subscribe status.'),
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      );
}        

Once you added 'serialize' => TRUE, drupal_write_record will do the work to serialize uc_mailchimp field.

web-beest’s picture

#11 did the trick for me. thanks fattshin!

web-beest’s picture

Issue summary: View changes

update on error