• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.