M
M
Maxim Klyushkov2012-08-31 20:26:57
PHP
Maxim Klyushkov, 2012-08-31 20:26:57

MSSQL query in PHP?

Good afternoon! For some, the question will seem silly, but I hope it will be answered ...
So, there is a MSSQL database. Through Microsoft SQL Server Management Studio I execute the query:

select count(DISTINCT stb.mac)
from [tve_34_sp1].[dbo].[SET_TOP_BOX] stb
inner join [tve_34_sp1].[dbo].[PARTY_ROLE] pr on stb.owner = pr.id
inner join [tve_34_sp1].[dbo].[PARTY] nm on pr.party = nm.id
inner join [tve_34_sp1].[dbo].[CUSTOMER] cs on stb.owner = cs.id
inner join [tve_34_sp1].[dbo].[SERVICE] ss on stb.owner = ss.customer
inner join [tve_34_sp1].[dbo].[SERVICE_SPECIFICATION] sp on ss.srv_spec = sp.id

where pr.name like 'Q%'
and sp.name like 'blabla';

And I get the number 178, everything is fine, but when I try to execute this request through PHP (apache2, linux), I get the result 0.
Here is the code:
<?php


$link = mssql_connect('1.2.3.4', 'sa', 'password');
    mssql_select_db('tve_34_sp1', $link);

$sql = "select count(DISTINCT stb.mac)
from [tve_34_sp1].[dbo].[SET_TOP_BOX] stb
inner join [tve_34_sp1].[dbo].[PARTY_ROLE] pr on stb.owner = pr.id
inner join [tve_34_sp1].[dbo].[PARTY] nm on pr.party = nm.id
inner join [tve_34_sp1].[dbo].[CUSTOMER] cs on stb.owner = cs.id
inner join [tve_34_sp1].[dbo].[SERVICE] ss on stb.owner = ss.customer
inner join [tve_34_sp1].[dbo].[SERVICE_SPECIFICATION] sp on ss.srv_spec = sp.id

where pr.name like 'Q%'
and sp.name like 'blabla'";

$sql = mssql_query($sql);

while($obResults = mssql_fetch_row($sql))
{
   echo $obResults[0];
}


mssql_close($link);
?>

Tell me what I did wrong?
Yes, I understand that the solution to use PHP is not the best…

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
gaelpa, 2012-08-31
@m_klyushkov

As a hypothesis: it is possible that the problem is in Collation. A colleague came across and solved it, so I can’t suggest the way to check / solve on the fly.

S
stan_jeremy, 2012-08-31
@stan_jeremy

what does mssql_get_last_message() say?

M
Maxim Klyushkov, 2012-09-01
@m_klyushkov

It looks like join requests are not being handled correctly...

H
Hint, 2012-09-02
@Hint

Check the results of the mssql_connect and mssql_select_db functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question