CodeIgniter Forums

Full Version: Loading a SQL file to run queries.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have the following.. I am trying to load a SQL file like this.

$params = array(
  'foo' => 'test',
  'bar' => 'case'
);

$filename = 'test.sql';
$sql = $this->load->file($filename, true);
$query = $this->sedona_db->query($sql,$params); 


the 'test.sql' file looks something like this:

Declare @foo varchar(10) = ?
Declare @bar varchar(10) = ?

Select * ... something something where foo = @foo
Exec someStoredProc @foo

--------------------------------------

I would get an error msg like this:
mssql_query(): message: Must declare the scalar variable "@foo"(severity 15)
I figured out the issue to this.

In the SQL file I needed to redeclare the params again in the code.
Because of the complexity of having multiple statements firing, the datatype of the params are lost in scope.