David Brooks David Brooks - 4 months ago 20
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
myquery.sql
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?

Answer

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.

Comments