Blog

28 Nov
2012

CodeIgniter Icon Logo

Call CodeIgniter MySQL query inside a helper file


This is a short snippet of php code if you want to use a CodeIgniter database query inside a helper file/function which is based in the following folder 'application/helpers/'.

<?php
// outputs the query results //
function array_output()
{  
    $ci=& get_instance();
    $ci->load->database(); 

    $sql = "SELECT * 
    FROM table"; 
    $query = $ci->db->query($sql);
    $row = $query->result();
    return $row;
}
?>
Tagged: < calling | codeigniter | database | helper | mysql | php | query >
Posted in: < PHP MVC >
me@grafxflow avatar

me@grafxflow


I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Visitors also viewed these posts

3 Thoughts

  1. 28 Sep
    2013

    avatar

    Darren

    Thank you!
    This worked perfectly!
  2. 28 Sep
    2013

    avatar

    me@grafxflow

    Glad to help.
  3. 16 Sep
    2014

    avatar

    Chinkush Varshney

    Hey Thanks its working......

Add comment

Add comment