0

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.

0

1 Answer 1

2
  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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.