Jump to content

core000

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

core000's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm using PHP to access SQL Server Stored Procedure. However, the characters are not returning correctly using JSON. Database value -------------- _ResourceGuid '341EEB0B-9D71-4805-8380-000C53BAE950' ResourceGuid '341EEB0B-9D71-4805-8380-000C53BAE950' status 'Active' PHP Returned JSON array ----------------------- [{"_ResourceGuid":"\u000b","Resourceguid":"\u000b","status":"Active","..... Code below: ------------------- <?php $myServer = "server"; $myUser = "user"; $myPass = "passw"; $myDB = "mydatabase"; $conn = mssql_connect($myServer, $myUser, $myPass, $myDB); $sql ="EXEC spassetreport"; /*$result = mssql_query("SET ANSI_NULLS ON") or die(mssql_get_last_message());*/ $result = mssql_query("SET ANSI_WARNINGS ON") or die(mssql_get_last_message()); $data = mssql_query( $sql, $conn); $result = array(); do { while ($row = mssql_fetch_object($data)){ $result[] = $row; } }while ( mssql_next_result($data) ); echo json_encode($result); mssql_close($conn); ?>
  2. I think I'm getting the array conversion wrong. I am trying to copy the results of the query from one array to another. However I am not sure how to assign name/value pairs into the array. Code below: <?php $myServer = "myserver.com"; $myUser = "user"; $myPass = "pass"; $myDB = "Northwind"; //create an instance of the ADO connection object $conn = new COM ( "ADODB.Connection" ) or die ( "Cannot start ADO" ); //define connection string, specify database driver $connStr = "PROVIDER=SQLOLEDB;SERVER=" . $myServer . ";UID=" . $myUser . ";PWD=" . $myPass . ";DATABASE=" . $myDB; $conn->open ( $connStr ); //Open the connection to the database //declare the SQL statement that will query the database $query = " SELECT * from Employees "; //execute the SQL statement and return records $rs = $conn->execute ( $query ); $num_columns = $rs->Fields->Count (); //echo $num_columns . "<br>"; $returnArray = array(); for($i = 0; $i < $num_columns; $i ++) { $fld [$i] = $rs->Fields ( $i ); } for($i = 0; $i < $num_columns; $i ++) { array_push($returnArray, $fld); } //Start the output of XML while ( ! $rs->EOF ) //carry on looping through while there are records { for($i = 0; $i < $num_columns; $i ++) { array_push($resultarray, $fld [$i]->value); //$rs->MoveNext (); } //move on to the next record } echo json_encode($returnArray); //close the connection and recordset objects freeing up resources $rs->Close (); $conn->Close (); $rs = null; $conn = null; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.