php 5.2 and MSSQL (sqlsrv driver 1.0) – tipe Bytes (links)??? – PHP




lang: php5.2.*
server: mssql express *.1399 (2005)
conn.driver: php_sqlsrv.dll (version 1.0)

i have a small table "Table01" at express server with fields:

id (int)
name (ntext)
company (bytes) – link to "Table02"

$query = sqlsrv_query($conn, ‘SELECT * FROM Table01’);

echo $massarray[$i][‘company’]."<br>";//bytes


function sql_fetch_all($query){
while( $row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
return $massarray;

The view of $massarray[$i][‘company’] is not correct..


Hi and welcome to Bytes. Please remember to wrap any code within [code][/code] tags.

Can you please give an example of what isn’t right about the return?

I can give you a tip right off the bat though, when creating a dynamic array in PHP, if you only want the array to be numbered, for example [0] = zero, [1] = one, etc. then you don’t need to specify a number in the brackets. You also don’t need to instantiate the array beforehand, simply calling $variable[] is enough to create the array. A better way to do your function would be:

function sql_fetch_all($query) {
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
$massarray[] = $row;
return $massarray;

This will do the exact same thing as your prvious function, but with less lines.

Also understand that you can’t echo an array, it will always only print "Array( )". To print an array, use print_r($array).

Hope this helps, please let me know if you have more questions.


it’s means:

for ($i=0;$i<count($massarray);$i++){
echo $massarray[$i]['company']."<br>";
$massarray["it's row number"]["it's SQLSRV_FETCH_ASSOC column - type is BYTE"]


i cann’t correct echo an array’s colimns with type is BYTE (link to "table02")


Ok, try commenting out your current function sql_fetch_all() and insert the one that I wrote in my first post, then comment out the line:

echo $massarray[$i][‘company’]."<br>";//bytes

and put this after it:

echo "<pre>";
echo "</pre>";

It won’t be formatted how you want, but does it return the data that you want? Does it have the SQLSRV_FETCH_ASSOC column data?


[0] => Array
[IDRRef] => "fdsg556fd3; //BYTE, not correct it's guid
[Marked] =>
[IsMetadata] =>
[ParentIDRRef] => «Яґ#lИS” //BYTE not correct
[Fld13] => DateTime Object //DATETIME


Well immediately I see that the "Company" column doesn’t exist in that table, so that might be your problem.

Is there any reason the data needs to be in BYTE form, why not text or int? I’m not sure what you’re going for here.