Hi, me again ;-)
So i have this code:
<?php
$db = new db();
$sql = "SELECT id FROM contentobject_a ttribute WHERE contentobject_i d=2
AND contentclassatt ribute_id=1";
$result = $db->query($sql);
while ($row = $result->fetch_assoc( )) {
$result2 = $db->query("SELEC T * FROM contentclass");
$version = $result2->fetch_assoc( );
echo var_dump($versi on)."<br />";
}
class db {
private $mysqli;
private $result;
function __construct() {
$this->mysqli = new mysqli("host", "user", "pass", "db");
}
function query($Query_St ring) {
if ($Query_String == "")
return 0;
// New query, discard previous result.
if ($this->result) {
$this->free();
}
$this->result = $this->mysqli->query($Query_S tring);
// Will return nada if it fails. That's fine.
return $this->result;
}
function free() {
$this->result->close();
}
}
?>
Try to run it and you get an warning. Now if i replace the free() method
with the following:
function free() {
$this->result->free;
}
everything works as expected. But if i try to use this in my app, apache
segfaults. Wanted to issue an Bug report, but cant reproduce it in an
small example.
So what can i do? Perhaps a small redesign of the class?
So i have this code:
<?php
$db = new db();
$sql = "SELECT id FROM contentobject_a ttribute WHERE contentobject_i d=2
AND contentclassatt ribute_id=1";
$result = $db->query($sql);
while ($row = $result->fetch_assoc( )) {
$result2 = $db->query("SELEC T * FROM contentclass");
$version = $result2->fetch_assoc( );
echo var_dump($versi on)."<br />";
}
class db {
private $mysqli;
private $result;
function __construct() {
$this->mysqli = new mysqli("host", "user", "pass", "db");
}
function query($Query_St ring) {
if ($Query_String == "")
return 0;
// New query, discard previous result.
if ($this->result) {
$this->free();
}
$this->result = $this->mysqli->query($Query_S tring);
// Will return nada if it fails. That's fine.
return $this->result;
}
function free() {
$this->result->close();
}
}
?>
Try to run it and you get an warning. Now if i replace the free() method
with the following:
function free() {
$this->result->free;
}
everything works as expected. But if i try to use this in my app, apache
segfaults. Wanted to issue an Bug report, but cant reproduce it in an
small example.
So what can i do? Perhaps a small redesign of the class?
Comment