David Brooks David Brooks - 11 months ago 48
PHP Question

Pass sql as string to controller in codeigniter

In my controller I have:

$query = $this->db->query("select * from table");

I want to have a file
in which the only contents of that file are:

select * from table

And so I can do something like:

$query = $this->db->query(myquery.sql);

What is the right syntax to do this?


You should be able to achieve that using:

$query = $this->db->query(file_get_contents('myquery.sql'));

Read more about file_get_contents.

You might need to use the correct path to myquery.sql, but that's the basic idea.