Welcome Guest, Not a member yet? Register   Sign In
Loading a SQL file to run queries.
#1

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)
Reply
#2

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB