Topic: What is faster?

I now have this code:

case 'process':
      $query = array (
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_script']).'\'', 'WHERE' => 'conf_name= \'o_gallery_script\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_show_bbcode']).'\'', 'WHERE' => 'conf_name= \'o_gallery_show_bbcode\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_upload_size']).'\'', 'WHERE' => 'conf_name= \'o_gallery_upload_size\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_upload_dir']).'\'', 'WHERE' => 'conf_name= \'o_gallery_upload_dir\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_extension']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_extension\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_usergroups']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_usergroups\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_disallowed_user']).'\'', 'WHERE' => 'conf_name= \'o_gallery_disallowed_user\'' ),
        array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_upload']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_upload\'' )
      );
      foreach ( $query as $update ) {
        $db->query_build ( $update ) or error (__FILE__, __LINE__);
      }
      require_once PUN_ROOT.'include/cache.php';
      generate_config_cache ( );
      redirect ( pun_link ( 'extensions/gallery/admin/gallery.php' ), $lang_gallery['update success'] );

Or is it faster if I do this?

case 'process':
  if ( $_POST['o_gallery_script'] != $pun_config['o_gallery_script'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_script']).'\'', 'WHERE' => 'conf_name= \'o_gallery_script\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_show_bbcode'] != $pun_config['o_gallery_show_bbcode'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_show_bbcode']).'\'', 'WHERE' => 'conf_name= \'o_gallery_show_bbcode\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_upload_size'] != $pun_config['o_gallery_upload_size'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_upload_size']).'\'', 'WHERE' => 'conf_name= \'o_gallery_upload_size\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_upload_dir'] != $pun_config['o_gallery_upload_dir'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_upload_dir']).'\'', 'WHERE' => 'conf_name= \'o_gallery_upload_dir\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_allowed_extension'] != $pun_config['o_gallery_allowed_extension'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_extension']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_extension\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_allowed_usergroups'] != $pun_config['o_gallery_allowed_usergroups'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_usergroups']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_usergroups\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_disallowed_user'] != $pun_config['o_gallery_disallowed_user'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_disallowed_user']).'\'', 'WHERE' => 'conf_name= \'o_gallery_disallowed_user\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }
  if ( $_POST['o_gallery_allowed_upload'] != $pun_config['o_gallery_allowed_upload'] ) {
    $query = array ( 'UPDATE' => 'config', 'SET' => 'conf_value=\''.$db->escape($_POST['o_gallery_allowed_upload']).'\'', 'WHERE' => 'conf_name= \'o_gallery_allowed_upload\'' );
    $db->query_build ( $update ) or error (__FILE__, __LINE__);
  }

  require_once PUN_ROOT.'include/cache.php';
  generate_config_cache ( );
  redirect ( pun_link ( 'extensions/gallery/admin/gallery.php' ), $lang_gallery['update success'] );

I think that the first is faster because in the time that the second script has to check if $_POST and $pun_config is the same the first script is already done with it I think;

What do you all think?

Re: What is faster?

None of them. You can set multiple fields to be updated for the same table. Use that feature.

Re: What is faster?

What feature are you talking about?

Re: What is faster?

1. You're using $db->query_build wrong
2. #1 is probably marginally faster than #2
3. Try and use isset before accessing variables that might not be set (eg: in POST).
4. I don't think Bekko read the code properly

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: What is faster?

Whoops. Indeed. Didn't see it was the config table.

Re: What is faster?

hmm, I think that most of the $_POST will be set if they hit the update button.

So the second code if not good the first is better!

I use the first code but how should I use $db->query_build then can you explain smartys.

Re: What is faster?

$_POST stuff should be set, but there are many reasons it won't. Trying for E_ALL compatibility is never a bad thing. wink
As for query builder, take a look at 1.3's source and see how query builder is used wink

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: What is faster?

ok, I will try those thing.

Thanks Smartys