Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Developing and testing locally, I always use the "or die()" after my db connections to report any errors that I might have with my queries, updates etc.

    So locally, when there is no error, obviously the text or error message in the die() doesnt execute.

    The problem I am having is that on our live machine, running Microsoft SQL, both the query and the die() command both run. Ive gone through the local php.ini file as well as the live machine's php.ini file, and they are the same except for some fundamental changes - file locations etc.

    If I run an update to a record in the DB, the record updates, but the die() command also executes killing off the redirect back, so the user sees a nice and ugly error screen, when actually there is no error.

    Has anyone else experienced this?

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    try using "or die(mysql_error());" just to see if mysql_error throws out anything.
    There and Back Again :Ogre:

  4. #3
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Thx for the reply nsr81,

    Firstly, Im running MSsql so I use mssql_get_last_message() to get any messages from the DB....

    And the problem is that at the moment it reply's "Changed database context to <DBname>" As I said in my first post, It seems on select commands everything is fine, but on updates or delete's both the error and the SQL execute.

  5. #4
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    sorry about that.

    At the moment I can't suggest anything, as I haven't worked with MSSQL much.
    There and Back Again :Ogre:

  6. #5
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    When I'm stuck like this, I put an echo statement that prints out the offending SQL and then run it through phpMyAdmin. That tells you the exact error message.
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  7. #6
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Let me explain properly. At the moment, I have an update query that runs that updates a user's details.

    Locally, it works fine, and after the query has run, the page redirects back and displays a updated message. No problems.

    Ive uploaded the app onto our live system. The DB on my local machine and that of the live machine are exactly the same. But when I try to update the users details, it updates the record, but it ALSO execute the die command, and prints out either the error, or as you say Ekstreme, the SQL if I choose to put it into the die(). If I run the sql on the live machines DB, It works, no errors.

    So then why is it that both the update and the die are executing? Doesnt make any sense to me...

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Sounds odd.

    I was thinking along the lines of inadequate access privileges (SELECT returns no errors and UPDATE does).
    As long as the query actually executes, you have all the neccessary privileges from your remote script.

    I did a google, and found this on the MS support pages.

    http://support.microsoft.com/kb/q197459/
    "These messages are considered to be normal behavior of the driver, and are purely informational."

    There seems to be a lot of different connection methods to MSSQL that would generate this message. If you search php.net (whole site search) for "changed database context", you'll also find some fixes for different connection methods. There are also some user notes added under [phpfunction]mssql_get_last_message[/phpfunction].

    In essence, it appears to be just a nuisance message.
    S. Rosland

  9. #8
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Quote Originally Posted by rosland
    it appears to be just a nuisance message
    thats exactly what it is....

    Ive now noticed that on an INSERT, it works fine. Ive been playing around with mssql_min_message_severity() and mssql_min_error_severity(). Strangely, a DELETE and UPDATE didnt return that database context message, but it didnt redirect, just a blank screen.

    So i can suppress the message, but it doenst execute the rest of the code....

    Im not too sure what to do about this. Last resort is taking out the die() command. That works.

  10. #9
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah, I was going to say to use mssql_affected_rows (would return zero if tried to delete row which does not exist). But apparently it doesnt exist.

  11. #10
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    This answers your question from the PHP documentation
    Returns: A MS SQL result resource on success, TRUE if no rows were returned, or FALSE on error.
    In other words you need to excplictly test for a return value of false:
    PHP Code:
    if (mssql_query($query) === false) {
        die(
    'Failure');

    The reason it works on one server and not another is amystery to me - I guess the configurations must be slightly different.

    To debug, I would also suggest doing a var_dump on different kinds of queries:
    PHP Code:
    var_dump(mssql_query($query)); 


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com