Does anyone have example php for webhooks to MSSQL?

  • bjorn.kvinge298
    Asked on June 26, 2017 at 3:54 PM

    Hi, I have tried to get data from webhooks to my Azure database using php, but with no luck.

     

    Now I have just managed to solve it with using mysql instead and with help from all the examples on this forum.

    But still I want to make this in Azure and with MSSQL.

    Can someone please share examples of php for communicate and send webhooks data to a MSSQL database?

     

    Thanks for any hints or tips :)

     

    Regards

    McQuinge

  • aubreybourke
    Replied on June 26, 2017 at 4:12 PM

    You can find some webhook php examples here:

    Webhook PHP Script Examples 

    (#3. specifically allows you to send your form data to a MySQL database).

  • bjorn.kvinge298
    Replied on June 26, 2017 at 4:24 PM

    Thanks aubreybourke, these was one of the examples that helped me understanding the communication to mysql.

    But I need examples of php scripts that can be used to MSSQL.

    So far I have managed to connect to the MSSQL database successfully, and I can query it.

     

    So I just need help with defining and sending data (I think).

     

    Regards

    McQuinge

  • David JotForm Support Manager
    Replied on June 26, 2017 at 6:26 PM

    We do not have examples with MSSQL. We only have with MySQL: https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP 

  • bjorn.kvinge298
    Replied on June 26, 2017 at 6:37 PM

    Ok, thanks!

     

    Desperate attempt on a php script, the connection is working.

    $conn = sqlsrv_connect($serverName, $connectionOptions);

     

    $fieldvalues = $_REQUEST['rawRequest'];

    $obj = json_decode($fieldvalues, true);

    $sid = $conn->real_escape_string($_REQUEST['submissionID']);

    $MekaniskAnsatt = $conn->real_escape_string($obj['q5_mekaniskAnsatt']);

    $ElektroAnsatt = $conn->real_escape_string($obj['q102_elektroAnsatt102']);

     

    $insertSql = "INSERT INTO Timeføring (SubmissionID, MekaniskAnsatt, ElektroAnsatt) 

    VALUES (?,?,?)";

    $params = array(&$_POST['$sid'], 

    &$_POST['$MekaniskAnsatt'], 

    &$_POST['$ElektroAnsatt']);

    $stmt = sqlsrv_query($conn, $insertSql, $params);

    ?>

     

    Regards

    McQuinge

  • liyam
    Replied on June 26, 2017 at 9:03 PM

    Hello McQuinge,

    Thank you for sharing the code with us. We'll gladly take note of this.

    I see that you are using the SQLSRV driver of the PHP Microsoft Drivers for SQL Server. The difference between MSSQL and MySQL when coding with PHP are function names on connecting to its database. Since the usage of PHP is more common with Linux and MySQL databases (and as this combination is most common on web hosting service providers), the guide that we have set to provide is for PHP and MySQL, with also the assumption that the account owner has already setup his PHP with MySQL properly.

    But it's not completely different when calling database functions. This may also further help you on coding PHP with MSSQL via SQLSRV: https://docs.microsoft.com/en-us/sql/connect/php/how-to-perform-transactions

    Here is also a list of functions available on PHP's website: http://php.net/manual/en/book.sqlsrv.php 

    If you have questions or if you still have hurdles on this matter, please let us know.