简体   繁体   English

在PHP中存储SQL Server数组

[英]Storing SQL Server array in PHP

I'm trying to run a SELECT statement on this SQL Server database (and store the rows as variables, in an associative array so I can insert into a mysql database), and getting a few errors I don't understand. 我正在尝试在此SQL Server数据库上运行SELECT语句(并将行存储为变量,在关联数组中,以便我可以插入到mysql数据库中),并获得一些我不理解的错误。

First of all 首先

Incorrect syntax near the keyword 'SELECT'. 关键字'SELECT'附近的语法不正确。

Query: 查询:

SELECT 
    id, accountType, displayName, uid, parentOrg
FROM 
    censored.datatable

I've only had experience with MySQL, so I don't see what is wrong with the select above. 我只有MySQL的经验,所以我没有看到上面的选择有什么问题。

Second issue(s)... The select statement above is passed to this function below as $query. 第二个问题...上面的select语句作为$ query传递给下面的函数。

function query($query){
    $data = mssql_init($query, $this->getCon());
    $var = array('id','accountType','displayName','uid','parentOrganization_id');
    $row = array();
    do {
        mssql_execute($data);
        //$data->mssql_bind($row['id'], $row['accountType'], $row['displayName'], $row['uid'],
       // $row['parentOrganization_id']);
        mssql_bind($data ,'@id', $var['id'], SQLFLT8, false, 10);
        mssql_bind($data ,'@accountType', $var['accountType'], SQLVARCHAR, false, 10);
        mssql_bind($data ,'@displayName', $var['displayName'], SQLVARCHAR, false, 10);
        mssql_bind($data ,'@uid', $var['uid'], SQLFLT8, false, 10);
        mssql_bind($data ,'@parentOrganization_id', $var['parentOrganization_id'], SQLFLT8, false, 10);
        while ($row = mssql_fetch_object($data)){
            array_push($row, [$row['id'], $row['accountType'], $row['displayName'], $row['uid'],
                $row['parentOrganization_id']]);
        }
    }while ( mssql_next_result($data) );
    return $row;
}

This is supposed to be storing each row of the result set into the associative array. 这应该是将结果集的每一行存储到关联数组中。 here's all the errors this query function comes back with 这是查询功能返回的所有错误

Warning: mssql_execute(): stored procedure execution failed in C:\\Users\\jmurdock\\Report\\HQDevBox.php on line 51[mssql_execute()] 警告:mssql_execute():第51行的C:\\ Users \\ jmurdock \\ Report \\ HQDevBox.php中的存储过程执行失败[mssql_execute()]
Warning: mssql_bind(): Unable to set parameter in C:\\Users\\jmurdock\\Report\\HQDevBox.php on line 58[mssql_bind, error appears for all mssql_binds... lines 54-58] 警告:mssql_bind():无法在第58行的C:\\ Users \\ jmurdock \\ Report \\ HQDevBox.php中设置参数[mssql_bind,所有mssql_binds出现错误...第54-58行]
Warning: mssql_fetch_object(): supplied resource is not a valid MS SQL-result resource in C:\\Users\\jmurdock\\Report\\HQDevBox.php on line 59 警告:mssql_fetch_object():提供的资源不是第59行的C:\\ Users \\ jmurdock \\ Report \\ HQDevBox.php中的有效MS SQL结果资源
Warning: mssql_next_result(): supplied resource is not a valid MS SQL-result resource in C:\\Users\\jmurdock\\Report\\HQDevBox.php on line 63[mssql_next_result] 警告:mssql_next_result():提供的资源不是第63行的C:\\ Users \\ jmurdock \\ Report \\ HQDevBox.php中的有效MS SQL结果资源[mssql_next_result]

I have a feeling a for loop would be better.. Any help would be appreciated. 我有一种感觉for循环会更好..任何帮助将不胜感激。 The connection is valid, I'm 95% sure. 连接有效,我95%肯定。

  1. Pretty sure you're supposed to make your mssql_bind() calls before mssql_execute() . 很确定你应该在mssql_bind() 之前调用你的mssql_execute()
  2. The 6th parameter to mssql_bind() is a boolean, the 7th is an integer. mssql_bind()的第6个参数是布尔值,第7个是整数。 Ref 参考
  3. $var is not an associative array, but you're referring to it like one. $var不是一个关联数组,但你指的是它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM