Link to home
Start Free TrialLog in
Avatar of mohan singh
mohan singhFlag for India

asked on

ODBC- stored procedure in php

I have stored procedure function in mssql server

Now I need to use that stored procedure in php to insert data in database so
my question
is this possible stored procedure in Php with odbc connection ?

if yes so please tell me how to insert data


Thank You
Mohan Singh
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Yes, it should be possible, try using the execute statement instead of the query in the below example.
http://php.net/manual/en/function.sqlsrv-execute.php
Avatar of mohan singh

ASKER

Hi Raja Jegan R
but i am using odbc not sqlsrv

If you know how to insert it in database so please tell me how to call it

My stored procedure function is  udp_add_update_contact it have TEN (10) parameter


Thank You
I am using odbc_execute Like this
<?php
        if(isset($_POST['signUp'])){
            $f = $_POST['fname'];
            $m = $_POST['mname'];
            $l = $_POST['lname'];
            $mo = $_POST['mobile'];
            $e = $_POST['email']; 
            $null = "NULL";
            $date = "2018-05-12";
            $stmt    = odbc_prepare($conn, 'CALL [dbo].[udp_add_update_contact](?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
            $success = odbc_execute($stmt, array($null,$null,$null,$null,$f,$m,$l,$null,$mo,$null,$null,$null,$e,$null,$null,$null,$null));             
        }
    ?>

Open in new window

And now I am getting error

odbc_execute(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '.'., SQL state 37000 in SQLDescribeParameter in


can you tell me what is my mistake in this code

Thank You
 Mohan Singh
I think you should add some apostrophe to your string type of value in your SQL query string variables and try.
<?php
if(isset($_POST['signUp'])){
      $f = $_POST['fname'];
      $m = $_POST['mname'];
      $l = $_POST['lname'];
      $mo = $_POST['mobile'];
      $e = $_POST['email'];
      $null = "NULL";
      $date = "2018-05-12";
      $stmt    = odbc_prepare($conn, 'CALL udp_add_update_contact(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
      
      $success = odbc_execute($stmt, array("NULL","NULL","NULL","NULL",$f,$m,$l,"NULL",$mo,"NULL","NULL","NULL",$e,"NULL","NULL","NULL","NULL"));

      If above not worked try this
      //$success = odbc_execute($stmt, array(NULL,NULL,NULL,NULL,$f,$m,$l,NULL,$mo,NULL,NULL,NULL,$e,NULL,NULL,NULL,NULL));
}
?>
Thank you for help but your code is not working

Can you tell me what is  Incorrect syntax in this line
[b]$stmt    = odbc_prepare($conn, 'CALL [dbo].[udp_add_update_contact](?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');[/b]

Open in new window


I am getting error incorrect syntax

Thank you
Mohan Singh
I think your calling syntax : [dbo].[udp_add_update_contact]
$stmt    = odbc_prepare($conn, 'CALL udp_add_update_contact(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); this is not working? still error coming
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You Julian Hansen
For your contribution

can you explain why we need {} this bracket
Thank you all of you
You are welcome.

The curly braces are escape characters that tell the ODBC driver to translate the contents into a native SQL call