473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

hi!

system:
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');
$massarray=sql_fetch_all($query);

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

sqlsrv_close($conn);

//=============================================
function sql_fetch_all($query){
$i=0;
$massarray=array();
while( $row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
$massarray[$i]=$row;
$i=$i+1;
}
return $massarray;
}

The view of $massarray[$i]['company'] is not correct..
Sep 8 '10 #1
6 2768
HaLo2FrEeEk
404 256MB
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:

Expand|Select|Wrap|Line Numbers
  1. function sql_fetch_all($query) {
  2.   while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
  3.     $massarray[] = $row;
  4.     }
  5.   return $massarray;
  6.   }
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.
Sep 8 '10 #2
sorry
it's means:

Expand|Select|Wrap|Line Numbers
  1. for ($i=0;$i<count($massarray);$i++){
  2. echo $massarray[$i]['company']."<br>";
  3. }
  4.  
  5. $massarray["it's row number"]["it's SQLSRV_FETCH_ASSOC column - type is BYTE"]
  6.  
  7.  
Sep 8 '10 #3
i cann't correct echo an array's colimns with type is BYTE (link to "table02")
Sep 8 '10 #4
HaLo2FrEeEk
404 256MB
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:

Expand|Select|Wrap|Line Numbers
  1. echo "<pre>";
  2. print_r($massarray);
  3. 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?
Sep 8 '10 #5
Expand|Select|Wrap|Line Numbers
  1.     [0] => Array
  2.         (
  3.             [IDRRef] => "fdsg556fd3; //BYTE, not correct it's guid
  4.             [Marked] => 
  5.             [IsMetadata] => 
  6.             [ParentIDRRef] => «Яґ#lИS” //BYTE not correct
  7.             [Fld13] => DateTime Object  //DATETIME
  8.                 (
  9.                 )
  10.         )
  11.  
Sep 8 '10 #6
HaLo2FrEeEk
404 256MB
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.
Sep 8 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Guillaume | last post by:
Hello, I have a strange problem while using mssql server driver: when i update/insert in/delete a table and want to redirect after, i have the following error message: CGI Error The specified...
16
by: davemateer | last post by:
Hi We have a current system: Linux / Apache / PHP4.x talking to Microsoft SQL 2000 Thinking about going to: Windows 2003 / PHP4.x talking to the same Microsoft SQL 2000 box...
7
by: Mark Knochen | last post by:
Hallo, i have a MS SQL Database with some tables with textfields. in the textfields are long strings ... but i cant get the full string from the table ... i get only ca. 8000 chars ... Mark
2
by: Martin Lukasik | last post by:
Hi, I'm using Sybase driver under Linux and I'm trying to connect to MSSQL server 2000. But unfortunately connection fails. In Event Log on my Win 2k3 SBS I'm getting the following error...
9
by: dunleav1 | last post by:
Does enabling/disabling Data Execution Prevention have a performance impact on SQL 2000 or SQL 2005? For SQL best performance - how should I configure for: Processor Scheduling: Programs or...
1
by: mkepick | last post by:
migrated databases from sybase to mssql, migration exported sybase written queries written with the application build in query tool and imported to mssql databases. all db and tables migrated...
0
by: exclaim | last post by:
Apologies if this is not the right forum. I have an application written originally to work with MySQL which now has to be extended to work with MSSQL also. I have modified all my database calls...
8
by: john6630 | last post by:
I am trying to get PDO for sqlite to work on my localhost system. I have modified the PHP5.ini file as shown below and run the following PHP script. As stated below, it reports the mssql, mysql and...
1
by: newphpcoder | last post by:
Actually, now I only test my webpage in a computer that I create as a server. And also I’m not too familiar in a server. Now I created a database in SQL Server 2005 Express and some of information I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.