CodeIgniter Forums
help with SqlServer Store Procedure - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forum-17.html)
+--- Thread: help with SqlServer Store Procedure (/thread-74660.html)



help with SqlServer Store Procedure - pabloesnp - 10-21-2019

I have a store procedure in Sql server2012. 
It has 1 parameter (dni)
when I try to call, if I dont write the parameter , the error say "the SP was waiting a parameter.
PHP Code:
public function llama_sp()
    {
      //  $query = $this->db->get('Personas');

        $dni'22555666';
      $this->db->trans_start();
     
      $query 
$this->db->query('execute SP_Alumnos_Mostrar');
      $this->db->trans_complete();
        return $query->result();
    
I receive this error: 

A Database Error Occurred
Error Number: 42000/201
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]El procedimiento o la función 'SP_Alumnos_Mostrar' esperaba el parámetro '@dni', que no se ha especificado.
execute SP_Alumnos_Mostrar
Filename: C:/xampp/htdocs/CodeIgniter3/system/database/DB_driver.php
Line Number: 691


If I write the parameter: 

PHP Code:
$query $this->db->query('execute SP_Alumnos_Mostrar($dni)'); 

I receive this error: 

A Database Error Occurred
Error Number: 42000/102
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Sintaxis incorrecta cerca de '$dni'.
execute SP_Alumnos_Mostrar($dni)
Filename: C:/xampp/htdocs/CodeIgniter3/system/database/DB_driver.php
Line Number: 691


I cant resolve. Please if somebody can help me.....
PD: sorry for my english 
Pablo


RE: help with SqlServer Store Procedure - mladoux - 10-21-2019

Well, I don't anything about mssql, however, when you use single quotes, instead of double quotes, php variable names don't get parsed, and thus the value of $dni doesn't get passed ( assuming it's being determined by php and not some special mssql key phrase )