473,395 Members | 1,696 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,395 software developers and data experts.

Help with MSSQL/PHP

Hi wondering if anyone can help.

What i'm trying to do is get a company from a MSSQL database with the
COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to
reference it to another table (on same database) to extract more details.

When I get the company name and company no the company no outputs like...
63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?

I wanted to reference another table so I...
$query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE
COMPANYNO='$companyno'";

And of course this wouldn't work and the error was:

Warning: Sybase message: Syntax error converting from a character string to
uniqueidentifier.

I need help with this as binary/hex sometimes goes over my head. If anyone
can point me in the right direction that would be great. I've had this same
problem before and did a crappy 'work around' - now i've realised why I did
the work around!

Thanks a lot for ANY help at all :)

(if nothing makes sense please say so :))

Darren
Jul 17 '05 #1
9 7243
On Thu, 13 Nov 2003 12:35:36 +0000 (UTC), "Darren" <ze**@zeen.co.uk>
wrote:
Hi wondering if anyone can help.

When I get the company name and company no the company no outputs like...
63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?


So really, you need to know what datatype that field is?

mysql_fetch_field($result) should get you an object holding the
appropriate information.

Jul 17 '05 #2
> >When I get the company name and company no the company no outputs like...
63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?


So really, you need to know what datatype that field is?

mysql_fetch_field($result) should get you an object holding the
appropriate information.


No no, i want to use the first SQL output of the GUID into another SELECT
and i get the error..

Warning: Sybase message: Syntax error converting from a character string to
uniqueidentifier.

I'm not sure how to use '63180001000000000000000000000000' GUID output into
another SQL SELECT.

(sorry for emailing you directly a second ago, haven't used newsgroups for
ages :P)
Jul 17 '05 #3
I have been looking at...

http://uk.php.net/manual/en/function...uid-string.php

But when using mssql_guid_string i get...

Fatal error: Call to undefined function: mssql_guid_string() in
/export/home/darrenm/web/scripts/guid.php on line 32.

php-4.3.1
freetds-0.61

and yes it was compiled with --enable-msdblib --with-tdsver=7.0

I guess this is the function i need!

If i do...

$query = "SELECT cast(COMPANYNO as varchar(36)),USERSTRING1 FROM CONTACT
WHERE USERSTRING1='$iusername'";

it gets one result (which is correct) but COMPANYNO is blank when i try and
print it (because it's something that can't be printed? i have no idea!)

Welp!
Jul 17 '05 #4
On Thu, 13 Nov 2003 14:43:34 +0000 (UTC), "Darren" <ze**@zeen.co.uk>
wrote:
No no, i want to use the first SQL output of the GUID into another SELECT
and i get the error..

Warning: Sybase message: Syntax error converting from a character string to
uniqueidentifier.

I'm not sure how to use '63180001000000000000000000000000' GUID output into
another SQL SELECT.


It is still a data representation problem. You need to find some
documentation on the syntactic representation of data types for the
Sybase SQL engine.

63180001 00000000 00000000 00000000

The above data looks like binary to me... or perhaps it is a complete
fluke that it splits nicely into a 64 bit word ?
kafooey
- ka*****@nospam.yahoo.co.uk
- http://www.pluggedout.com/blog
Jul 17 '05 #5
"Darren" <ze**@zeen.co.uk> wrote in message
news:bo**********@sparta.btinternet.com...
Hi wondering if anyone can help.

What i'm trying to do is get a company from a MSSQL database with the
COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to reference it to another table (on same database) to extract more details.
Somebody (or you) have misunderstood the 'uniqueidentifier' datatype
of MSSQL. 'uniqueidentifier' is *not* an integer/autoincrement value
often used as "synthetic" primary keys!

The uniqueidentifier data type stores 16-byte binary values that operate
as globally unique identifiers (GUIDs). A GUID is a unique binary number;
no other computer in the world will generate a duplicate of that GUID value.
The main use for a GUID is for assigning an identifier that must be unique
in a network that has many computers at many sites.

It is usually of the form:
* Character string format
'6F9619FF-8B86-D011-B42D-00C04FC964FF'

* Binary format
0xff19966f868b11d0b42d00c04fc964ff

The thing i suspect you want is an "int identity" Primary key, and you make
one like this:
create table CONTACT
(
Id_Contact int identity,
Name int not null,
Phone varchar(255) null,
constraint PK_Contact primary key (Id_Contact)
)
go

--
Dag.


When I get the company name and company no the company no outputs like...
63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?

I wanted to reference another table so I...
$query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE
COMPANYNO='$companyno'";

And of course this wouldn't work and the error was:

Warning: Sybase message: Syntax error converting from a character string to uniqueidentifier.

I need help with this as binary/hex sometimes goes over my head. If anyone
can point me in the right direction that would be great. I've had this same problem before and did a crappy 'work around' - now i've realised why I did the work around!

Thanks a lot for ANY help at all :)

(if nothing makes sense please say so :))

Darren

Jul 17 '05 #6
Forget I said something, Darren!

(Just read your follow-up posts, and it seems you are
aware of what a GUID is).

:-)

--
Dag.
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f******@news.wineasy.se...
"Darren" <ze**@zeen.co.uk> wrote in message
news:bo**********@sparta.btinternet.com...
Hi wondering if anyone can help.

What i'm trying to do is get a company from a MSSQL database with the
COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to
reference it to another table (on same database) to extract more details.
Somebody (or you) have misunderstood the 'uniqueidentifier' datatype
of MSSQL. 'uniqueidentifier' is *not* an integer/autoincrement value
often used as "synthetic" primary keys!

The uniqueidentifier data type stores 16-byte binary values that operate
as globally unique identifiers (GUIDs). A GUID is a unique binary number;
no other computer in the world will generate a duplicate of that GUID value. The main use for a GUID is for assigning an identifier that must be unique
in a network that has many computers at many sites.

It is usually of the form:
* Character string format
'6F9619FF-8B86-D011-B42D-00C04FC964FF'

* Binary format
0xff19966f868b11d0b42d00c04fc964ff

The thing i suspect you want is an "int identity" Primary key, and you make one like this:
create table CONTACT
(
Id_Contact int identity,
Name int not null,
Phone varchar(255) null,
constraint PK_Contact primary key (Id_Contact)
)
go

--
Dag.


When I get the company name and company no the company no outputs
like... 63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?

I wanted to reference another table so I...
$query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE
COMPANYNO='$companyno'";

And of course this wouldn't work and the error was:

Warning: Sybase message: Syntax error converting from a character string to
uniqueidentifier.

I need help with this as binary/hex sometimes goes over my head. If

anyone can point me in the right direction that would be great. I've had this

same
problem before and did a crappy 'work around' - now i've realised why I

did
the work around!

Thanks a lot for ANY help at all :)

(if nothing makes sense please say so :))

Darren


Jul 17 '05 #7
I think i found the answer...

You can't compare a 'uniqueidentifier' to just any string,
it *MUST* be on the format (Like a GUID:

'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

Where each x is a hex digit. So you must convert your number
to hex, and add the hypens...

63180001000000000000000000000000
'00000000-0000-0000-D12F-846681000000'

hth...

--
Dag
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f********@news.wineasy.se...
Forget I said something, Darren!

(Just read your follow-up posts, and it seems you are
aware of what a GUID is).

:-)

--
Dag.
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f******@news.wineasy.se...
"Darren" <ze**@zeen.co.uk> wrote in message
news:bo**********@sparta.btinternet.com...
Hi wondering if anyone can help.

What i'm trying to do is get a company from a MSSQL database with the
COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I
want
to
reference it to another table (on same database) to extract more details.

Somebody (or you) have misunderstood the 'uniqueidentifier' datatype
of MSSQL. 'uniqueidentifier' is *not* an integer/autoincrement value
often used as "synthetic" primary keys!

The uniqueidentifier data type stores 16-byte binary values that operate
as globally unique identifiers (GUIDs). A GUID is a unique binary

number; no other computer in the world will generate a duplicate of that GUID

value.
The main use for a GUID is for assigning an identifier that must be unique in a network that has many computers at many sites.

It is usually of the form:
* Character string format
'6F9619FF-8B86-D011-B42D-00C04FC964FF'

* Binary format
0xff19966f868b11d0b42d00c04fc964ff

The thing i suspect you want is an "int identity" Primary key, and you

make
one like this:
create table CONTACT
(
Id_Contact int identity,
Name int not null,
Phone varchar(255) null,
constraint PK_Contact primary key (Id_Contact)
)
go

--
Dag.


When I get the company name and company no the company no outputs like... 63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?

I wanted to reference another table so I...
$query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE
COMPANYNO='$companyno'";

And of course this wouldn't work and the error was:

Warning: Sybase message: Syntax error converting from a character string
to
uniqueidentifier.

I need help with this as binary/hex sometimes goes over my head. If

anyone can point me in the right direction that would be great. I've had this

same
problem before and did a crappy 'work around' - now i've realised why

I did
the work around!

Thanks a lot for ANY help at all :)

(if nothing makes sense please say so :))

Darren



Jul 17 '05 #8
Hi Darren!

On Thu, 13 Nov 2003 12:35:36 +0000 (UTC), "Darren" <ze**@zeen.co.uk>
wrote:
Hi wondering if anyone can help.

What i'm trying to do is get a company from a MSSQL database with the
COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to
reference it to another table (on same database) to extract more details.

When I get the company name and company no the company no outputs like...
63180001000000000000000000000000
In basic terms I'm only getting it like...
$query = "SELECT COMPANYNO FROM CONTACT";

Now I know this isn't a 16 byte binary - is it?

I wanted to reference another table so I...
$query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE
COMPANYNO='$companyno'";


Apart from your problems, can't you use a join and one query or even a
view?

HTH, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #9
Excellent, I'll give this a shot!

Cheers

:Darren
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f********@news.wineasy.se...
I think i found the answer...

You can't compare a 'uniqueidentifier' to just any string,
it *MUST* be on the format (Like a GUID:

'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

Where each x is a hex digit. So you must convert your number
to hex, and add the hypens...

63180001000000000000000000000000
'00000000-0000-0000-D12F-846681000000'

hth...

--
Dag
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f********@news.wineasy.se...
Forget I said something, Darren!

(Just read your follow-up posts, and it seems you are
aware of what a GUID is).

:-)

--
Dag.
"Dag Sunde" <da******@orion.no.way> wrote in message
news:3f******@news.wineasy.se...
"Darren" <ze**@zeen.co.uk> wrote in message
news:bo**********@sparta.btinternet.com...
> Hi wondering if anyone can help.
>
> What i'm trying to do is get a company from a MSSQL database with the > COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to
> reference it to another table (on same database) to extract more details.

Somebody (or you) have misunderstood the 'uniqueidentifier' datatype
of MSSQL. 'uniqueidentifier' is *not* an integer/autoincrement value
often used as "synthetic" primary keys!

The uniqueidentifier data type stores 16-byte binary values that operate as globally unique identifiers (GUIDs). A GUID is a unique binary number; no other computer in the world will generate a duplicate of that GUID

value.
The main use for a GUID is for assigning an identifier that must be unique in a network that has many computers at many sites.

It is usually of the form:
* Character string format
'6F9619FF-8B86-D011-B42D-00C04FC964FF'

* Binary format
0xff19966f868b11d0b42d00c04fc964ff

The thing i suspect you want is an "int identity" Primary key, and you

make
one like this:
create table CONTACT
(
Id_Contact int identity,
Name int not null,
Phone varchar(255) null,
constraint PK_Contact primary key (Id_Contact)
)
go

--
Dag.
>
> When I get the company name and company no the company no outputs

like...
> 63180001000000000000000000000000
> In basic terms I'm only getting it like...
> $query = "SELECT COMPANYNO FROM CONTACT";
>
> Now I know this isn't a 16 byte binary - is it?
>
> I wanted to reference another table so I...
> $query = "SELECT ACTIVITYHEADERNO,COMPANYNO FROM ACTIVITYHEADER WHERE > COMPANYNO='$companyno'";
>
> And of course this wouldn't work and the error was:
>
> Warning: Sybase message: Syntax error converting from a character

string
to
> uniqueidentifier.
>
> I need help with this as binary/hex sometimes goes over my head. If

anyone
> can point me in the right direction that would be great. I've had this same
> problem before and did a crappy 'work around' - now i've realised
why I did
> the work around!
>
> Thanks a lot for ANY help at all :)
>
> (if nothing makes sense please say so :))
>
> Darren
>
>



Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: badz | last post by:
Hi frenz Lately I try to use MSSQL and PHP , the problem arise when PHP try to read MSSQL field with 'image' data type, header("Content-type: image/jpeg"); // act as a jpg file to browser I...
2
by: bigoxygen | last post by:
Hi. I am experiencing problems connecting to MSSQL. I'm not sure where to begin looking for the problem. I don't know if the problem is originating with PHP or MSSQL What should the host name...
0
by: Lindstrom Greg - glinds | last post by:
I would like to use Python (2.3.3 on Windows 2000 "Professional") to access a MSSQL Server and list all of the available databases, as well as the tables in each database and columns in each table...
0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
1
by: Houston | last post by:
I have been able to get several basic databases to function both in playing around and functional ones on the web but they have all been pretty simple. I am now trying to develop a database for the...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try...
14
by: guswebb | last post by:
Hi. I'm a newbie to PHP and am having a few problems as follows... I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to...
2
by: wizdom | last post by:
I'm trying to add simple page support, the page is php/mssql based. Anyone know why this doesn't work? I found the "NOT IN" command online but I'm not 100% sure about it..... any help is...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.