Hi. I was contemplating purchasing a copy of "Wrox CodeIgniter Professional 2008", and I was having a look at the free sample chapter. The are two places on the page where $q->free_result() is called after the return statement.
PHP Code:
<?php
class Page_model extends Model{
function Page_model(){
parent::Model();
}
function fetchHomePage(){
$data = array();
$options = array(âstatusâ => âliveâ, âtypeâ=> âhomeâ);
$q = $this->db->getwhere(âpagesâ, $options, 1);
if ($q->num_rows() > 0){
$data = $q->row_array();
}
return $data;
$q->free_result();
}
}
?>
and
PHP Code:
<?php
class Page_model extends Model{
function Page_model(){
parent::Model();
}
function fetchHomePage(){
$data = array();
$options = array(âstatusâ => âliveâ, âtypeâ=> âhomeâ);
$q = $this->db->getwhere(âpagesâ, $options, 1);
if ($q->num_rows() > 0){
$row = $q->row();
$data[âtitleâ] = $row->title;
$data[âcssâ] = $row->css;
$data[âkeywordsâ] = $row->keywords;
$data[âdescriptionâ] = $row->description;
$data[âbodycopyâ] = nl2br($row->bodycopy);
}
return $data;
$q->free_result();
}
}
?>
This could be a simple mistake, but it's repeated twice on the page and should have been picked up on during proof-reading. Here's what PHP says about the return statement:
Quote:
|
If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call.
|
So basically, $q->free_result() will never be reached as it appears immediately after the return statement.
Would anybody recommend the book? I'm still interested in purchasing it, but I have my doubts as to how accurate the rest of the information may be.
Thanks in advance.