David Brooks David Brooks - 1 year ago 75
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download