dongshipang8094 2013-12-18 00:19
浏览 34
已采纳

在PHP中存储SQL Server数组

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.

First of all

Incorrect syntax near the keyword '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.

Second issue(s)... The select statement above is passed to this function below as $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()]
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]
Warning: mssql_fetch_object(): supplied resource is not a valid MS SQL-result resource in C:\Users\jmurdock\Report\HQDevBox.php on line 59
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]

I have a feeling a for loop would be better.. Any help would be appreciated. The connection is valid, I'm 95% sure.

  • 写回答

1条回答 默认 最新

  • dongti7838 2013-12-18 01:05
    关注
    1. Pretty sure you're supposed to make your mssql_bind() calls before mssql_execute().
    2. The 6th parameter to mssql_bind() is a boolean, the 7th is an integer. Ref
    3. $var is not an associative array, but you're referring to it like one.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名