Ben mysqli free () fonksiyonu ile ilgili bir sorun yaşıyorsanız

2 Cevap php

Ben bu yüzden gibi veritabanına bağlı kodu vardır:

$db = new mysqli("localhost", "user", "pass", "company");

Şimdi ben şöyle veritabanını sorgulamak zaman:

//query calls to a stored procedure 'user_info' 
$result = $db->query("CALL user_info('$instruc', 'c_register', '$eml', '$pass', '')");
if($result->fetch_array())
{
   //use the results
}
$result->close();

$result = $db->query("CALL user_info('$instruc', 's_login', '$eml', '$pass', '')");
if($result->fetch_array())
{
   //use the results
}
$result->close();

I get this error after the first $result->close(); Fatal error: Call to a member function fetch_array() on a non-object in... For me to run this other query I have to close the db conection and connect again, then it will work. I want to know if there is a way I could run the other query without having to disconnect and reconnect to the database.

şimdiden teşekkürler.

2 Cevap

free() sonuç kümesi ile herhangi bir veri stored in connection kaldırır, ama $result nesnenin kendisi, yani $result hala unset ayarlı değil mükemmel tamam.

Ancak yine de, $db nesnesini kullanarak yeni bir sorgu başlamak gerekir. Bir sonuç kümesi boşaltma veritabanı nesnesini kendisi etkilememelidir.

Eğer free() çalıştırdıktan sonra sonuç nesne üzerinde başarısız olur ve ne hata döndürür sorgu tam kod gösterebilir miyim?

Basit bir örnek aşağıda verilmiştir:

$query='select ml_id, list_name from ml_lists order by list_name asc';
$squery=$db->query($query);

    while($rows=$squery->fetch_assoc()){
        echo $rows['list_name'];
    }
}
$squery->close();