Bu mysql_free_result ($ sonuç) kullanmak iyi bir uygulamadır?

3 Cevap php

Ben tüm ilişkili sonuç hafıza otomatik olarak betiğin yürütme sonunda serbest olduğunu farkındayım. Ben aşağıdaki gibi biraz benzer eylemlerin sürü oldukça kullanıyorum Ama eğer, bunu kullanarak tavsiye ederim?

$sql = "select * from products";
$result = mysql_query($sql);
if($result && mysql_num_rows($result) > 0) {
  while($data = mysql_fetch_assoc($result)) {
     $sql2 = "insert into another_table set product_id = '".$data['product_id']."'
              , product_name = '".$data['product_name']."'
             ";
     $result2 = mysql_query($sql2);
     **mysql_free_result($result2);**  
  }
}

Teşekkürler.

3 Cevap

It depends on how large your queries are or how many queries you run. PHP frees the memory at the end of the script(s) automatically, but not during the run. So if you have a large amount of data comming from a query, better free the result manually.

Diyorum ki: EVET, geliştirme veya komut sırasında hafızasına umurumda çünkü iyi bir uygulama olduğunu ve iyi bir geliştirici :-) ne yapar

Ne de içeride işlevlerini içeren bir sayfa bir php komut dosyası var durumlarda ilgili? Register komut örneğin bu gibi bazı şey:

    if (email_exists($email) === false) {
        $errors[] = 'We have a problem with your email address';

    } else if (activate($email, $email_code) === false) {
        $errors[] = 'Sorry, problems activating your account';
    }

hem email_exists ve etkinleştirmek içinde SELECT sorguları var. Iyi bir uygulama da işlevi sonunda mysql_free_result () ekleyin ve sonra değerleri döndürmek için i ya da mıyım?