Re: {CodeIgniter Kenya} Digest for codeigniter-kenya@googlegroups.com - 1 Message in 1 Topic

22 views
Skip to first unread message

Nd'wex Common

unread,
Aug 19, 2013, 9:14:41 AM8/19/13
to codeigni...@googlegroups.com
two pieces of info
1. CI 2.1.4 out around july making it a month old
2. EllisLab is looking for a new owner for CI
The above info can be confirmed and read in-depth from EllisLab website

Happy Coding


On Mon, Aug 5, 2013 at 10:11 AM, <codeigni...@googlegroups.com> wrote:

Group: http://groups.google.com/group/codeigniter-kenya/topics

    Peter Karunyu <pkar...@gmail.com> Aug 04 06:28PM +0300  

    Using the world database, I have run this query which should return 209
    rows:
    *$rs = $this->db->query("SELECT * FROM country");*
     
    And var_dump($rs) gives:
    *object(CI_DB_mysql_result)#14 (8) { ["conn_id"]=> resource(7) of type
    (mysql link persistent) ["result_id"]=> resource(8) of type (mysql result)
    ["result_array"]=> array(0) { } ["result_object"]=> array(0) { }
    ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0)
    ["num_rows"]=> int(239) ["row_data"]=> NULL }
     
    *
    Now, if I run this query which should return zero results:*
    $rs = $this->db->query("SELECT * FROM country WHERE CODE='ABC'");
     
    *
    var_dump($rs) gives: *
    object(CI_DB_mysql_result)#14 (8) { ["conn_id"]=> resource(6) of type
    (mysql link persistent) ["result_id"]=> resource(7) of type (mysql result)
    ["result_array"]=> array(0) { } ["result_object"]=> array(0) { }
    ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0)
    ["num_rows"]=> int(0) ["row_data"]=> NULL } *
     
    So, i think a query that returns no results does NOT return false, it
    returns the same object a successful query does, only that the sub-objects
    i.e. $rs->result(), do not have any data.
     
    If I run this erroneous query:*
    $rs = $this->db->query("SELECT * FROM non_existent_table");*
     
    CI throws a database error such as:
    *A Database Error Occurred
    Error Number: 1146
    Table 'world.non_existent_table' doesn't exist
    SELECT * FROM non_existent_table
    Filename: /Users/Peter/Sites/ci_test/controllers/welcome.php
    Line Number: 22*
     
    Now, in a production environment, I don't want to be showing such a
    descriptive error to users, I want to show a different error message, AND
    log the occurrence of that said to the log files, and possibly send myself
    an email.
     
    To achieve this:
    1. The ENVIRONMENT in index.php will be set to PRODUCTION
    2. In config/database.php, *$db['default']['db_debug'] = TRUE;* will be set
    to FALSE.
    3. In config/config.php, $config['log_threshold'] = 0; will be set to at
    least 1.
     
    Therefore, modifying your code slightly, I end up with this:
     
    *$rs = $this->db->query("SELECT * FROM non_existent_table");
     
    if ($rs == FALSE) {
    log_message('error', "DB Error: (".$this->db->_error_number().")
    ".$this->db->_error_message(). ' Path: '.$this->uri->uri_string());
    show_error('Sorry, a database error occurred, Tech Support has been
    notified. Please try again later.');
    return FALSE;
    }
     
    if($rs->num_rows() > 0)
    {
    $rs = $rs->result(); //returns an array of objects
     
    foreach($rs as $objects)
    {
    //do something with the data here
    }
     
    return $something;
    }
     
    return FALSE;
     
    *
     
     
     
    --
    Regards,
    Peter Karunyu
    -------------------

     

--
You received this message because you are subscribed to the Google Groups "CodeIgniter Kenya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codeigniter-ke...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Peter Karunyu

unread,
Aug 21, 2013, 5:03:18 AM8/21/13
to codeigni...@googlegroups.com
I wonder whats going to happen to CI in the recent future...
Reply all
Reply to author
Forward
0 new messages