Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

MSSQL, SOAP, PHP

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: macek, egami, gesf

MSSQL, SOAP, PHP

Postby donkey » Thu Jul 21, 2005 3:39 am

Hi,

I have kind-of a problem. I've been working on a web service, which comunicates with a MSSQL server. The problem is that mssql functions don't seem to return a value 'FALSE' when an error occures. this only happens when I use them inside the function of the web service server php file, which creates it's own WSDL file. If i use the code in a simple php page it works ok.
here is some of the code:
Code: Select all
<?
class SQL {
        .....
      function SELECT($sql, $db) {
       if(!($db_link = mssql_connect('MUHA','root','pseto')))
       {
                       ...same problem
       }

        if(!($db_s = mssql_select_db($db, $db_link)))
        {
           $return[0] = 'failed';
         return new SOAP_Value('return','{urn:SQL}ArrayOfStrings',$return);
      }
      $return[0] = 'OK';
      return new SOAP_Value('return','{urn:SQL}ArrayOfStrings',$return);
        }
        .....
}
....
?>
 

If I run this code with a database name that does not exist, the page freezes till a timeout occures, or some other strange stuf :)
The thing that if I use a mysql database and mysql_select_db() it works just fine.

Any ideas why this would be so??
Any body had the same problem??
Thank you
donkey
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 21, 2005 3:16 am

Postby ruturajv » Tue Jul 26, 2005 10:55 am

you can use

Code: Select all
<?php

if ($res = mssql_query($sql)) {
  // successfull query
} else {
  // false
}

?>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby gesf » Tue Jul 26, 2005 3:07 pm

Also if your first IF statement doesn't work, consenquently, your mssql_select_db() wont work too because of the link identifier ($db_link).
So like ruturajv example... try working around those IF statements... I bet it would be something related to it.
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby donkey » Tue Jul 26, 2005 11:24 pm

I'm not sure you comepletely understand. All the code works comepletely fine IF I use a mysql database an the statements related to it (mysql_coonect, mysql_select_database...). The problem occures when I try the code on an mssql database with proper mssql statements. Even this works fine just as long as the user does not make a mistake while entering the data. But when the user makes a mistake and, for example, the writen database name does not exist the whole thing stops working till a timeout occures on the client side. I tried every piece of code separately. Works fine. Even in a function. But when I stick it into a class... thats when it happens (just for mssql).
Any more suggestions?

Thank you
donkey
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 21, 2005 3:16 am

Postby gesf » Wed Jul 27, 2005 12:56 am

Yep i understood and thats a weird problem... thats why sometimes we got to play with code to better fit our needs.
Try something like:
Code: Select all
<?
class SQL {
  // .....
  function SELECT($sql, $db) {
     $db_link = (mssql_connect('MUHA','root','pseto')) ? 1 : 0;
     if(!$db_link){
        // ...same problem
     }else {
        $db_s = (mssql_select_db($db, $db_link)) ? 1 : 0;
        $return[0] = 'OK';
        return new SOAP_Value('return','{urn:SQL}ArrayOfStrings', $return);
     }
       
     if(!$db_s) {
        $return[0] = 'failed';
        return new SOAP_Value('return','{urn:SQL}ArrayOfStrings', $return);
     }

  }
  // .....
}
// ....
?>
I really can't see a reason for this problem. Actually the only thing which seems to be causing this are the IF's statements.

--
Out from job now, so got to sleep, but... will take a better look at this problem ASAP.
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby donkey » Wed Jul 27, 2005 2:13 am

Do you think this could be some kind of bug in the mssql package?
donkey
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 21, 2005 3:16 am

Postby Alexej Kubarev » Wed Jul 27, 2005 3:00 am

doesnt have to be a BUG.. it could simply be the way mssql package works and you should seriously read through whe documentation for that package and see the differences..
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby ruturajv » Thu Aug 04, 2005 9:20 pm

you need to specify the port 1433
soe
Code: Select all
<?php
mssql_connect(192.168.0.23:1433, 'usrename', 'password'); // for linux
mssql_connect(192.168.0.23,1433, 'usrename', 'password'); // for windows
?>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.