[eluser]Benjamin David[/eluser]
Hi !
I'm having a weird bug with the active record class. It's as if it remembers the where conditions I had made in previous queries. Here it is :
Here is the first function, it's a recursive one :
Code:
function delete_media_entry($id) {
if($id == 0) {
return FALSE;
}
$rip_medias = array();
$errors = 0;
$delete_root_media = new Media_model;
$rip_medias[$id] = $delete_root_media->get_media($id);
echo "get ($id)<br />";
echo $this->db->last_query();
/*if(!is_object($rip_medias[$id])) {
var_dump($rip_medias[$id]);
echo "<br />".$id;
}*/
if($rip_medias[$id]->file_type == 'folder') {
$medias = new Media_model;
$medias = $medias->get_medias($id);
foreach($medias as $media) {
if(!is_object($media)) {
//var_dump();
}
if($media->file_type == 'folder') {
/* recursion */
echo "<br />----recursion----<br />";
$this->delete_media_entry($media->id);
//echo "dossier: ".$media->name."(".$media->id.")<br />";
} else {
//echo "fichier:".$media->name."(".$media->id.")<br />";
$rip_medias[$media->id] = $media;
}
}
}
/* suppression des entrees */
foreach($rip_medias as $rip_media) {
$delete_media = new Media_model;
$delete_result = $delete_media->_delete_media_row($id);
if($delete_result == FALSE) {
$errors++;
}
}
if($errors == 0) {
return TRUE;
}
return FALSE;
}
Here is the second one that gets the media:
Code:
function get_media($id)
{
$this->db->where(array('id' => $id));
$query = $this->db->get($this->tables['media']);
if($query->num_rows() == 1) {
$media_row = $query->row();
$media_object = $this->set_db_object($media_row);
//echo $this->db->last_query()."<br />";
return $media_object;
}
//echo $this->db->last_query()."<br />";
return false;
}
I have some data in the table but the errors I'm getting are weird. In that case, I only ask for one row, I give the id and I'm awaiting a single row answer. But at some point, there is something that makes the class remember my previous where condition, but can't get to handle where... I'm wondering why it doesn't the db where function doesn't seem to reset after each query has run.
By the way, here's a copy of the errors I'm getting. Thanks for helping !
Code:
get (2)
SELECT * FROM arc_media WHERE id = '2'
----recursion----
get (5)
SELECT * FROM arc_media WHERE id = '5'
----recursion----
get (6)
SELECT * FROM arc_media WHERE id = '6'
----recursion----
get (9)
SELECT * FROM arc_media WHERE id = '6' AND id = '6' AND id = '5' AND id = '5' AND id = '9' LIMIT 1
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/media_model.php
Line Number: 63
----recursion----
get (10)
SELECT * FROM arc_media WHERE id = '9' AND id = '10' LIMIT 1
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/media_model.php
Line Number: 63
----recursion----
get (11)
SELECT * FROM arc_media WHERE id = '10' AND id = '11' LIMIT 1
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/media_model.php
Line Number: 63