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
LVL 3
mohan singhWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
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
1
mohan singhWeb developerAuthor Commented:
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
0
mohan singhWeb developerAuthor Commented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Swatantra BhargavaTechnical Specialist/DeveloperCommented:
I think you should add some apostrophe to your string type of value in your SQL query string variables and try.
0
Swatantra BhargavaTechnical Specialist/DeveloperCommented:
<?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));
}
?>
0
mohan singhWeb developerAuthor Commented:
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
0
Swatantra BhargavaTechnical Specialist/DeveloperCommented:
I think your calling syntax : [dbo].[udp_add_update_contact]
0
Swatantra BhargavaTechnical Specialist/DeveloperCommented:
$stmt    = odbc_prepare($conn, 'CALL udp_add_update_contact(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); this is not working? still error coming
0
Julian HansenCommented:
Just a note
 $null = "NULL";

Open in new window

Creates the string "NULL" not the value NULL. If you want to insert a null value then use
$null = null;

Open in new window

Also try calling your procedure as (note the query is wrapped in { }
$stmt    = odbc_prepare($conn, '{CALL udp_add_update_contact(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}');

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mohan singhWeb developerAuthor Commented:
Thank You Julian Hansen
For your contribution

can you explain why we need {} this bracket
0
mohan singhWeb developerAuthor Commented:
Thank you all of you
0
Julian HansenCommented:
You are welcome.

The curly braces are escape characters that tell the ODBC driver to translate the contents into a native SQL call
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.