pdo OPENJSON插入php无法正常工作(Azure SQL)

时间:2017-03-03 07:43:56

标签: php sql sql-server pdo azure-sql-database

通常,此代码在Visual Studio中用作T-SQL脚本,但在我添加的T-SQL中除外:

declare @json nvarchar(MAX) = '{...}'

@json进入OPENJSON函数

我正在尝试为OPENJSON插件创建一个PHP脚本,但这似乎不起作用。我是所有Azure / SQL / PHP的初学者。

有关OPENJSON功能的参考: https://blogs.msdn.microsoft.com/sqlserverstorageengine/2015/09/22/openjson-the-easiest-way-to-import-json-text-into-table/

<?php
    include_once("connection.php");
    $JSONrow = $_POST["jsonrow"];
    $table = $_POST["table"];
    $with = "(jobticketnumber nvarchar(50), contractor nvarchar(50),joblocation nvarchar(50), ...";

    $pdo_JSONinsert = $conn -> prepare('INSERT INTO '.$table.' SELECT * FROM OPENJSON('.$JSONrow.') WITH '.$with.'');
    $pdo_JSONinsert -> execute();

    $conn = null; 
?>

感谢您的帮助!

编辑:来自PDO的错误

<br />
<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server]Syntax error, permission violation, or other nonspecific error in D:\home\site\wwwroot\insertrow.php:7
Stack trace:
#0 D:\home\site\wwwroot\insertrow.php(7): PDO-&gt;prepare('INSERT INTO job...')
#1 {main}
  thrown in 
<b>D:\home\site\wwwroot\insertrow.php</b> on line 
<b>7</b>
<br />

0 个答案:

没有答案