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 6 of 6

Thread: mssql_query()

  1. #1
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    This is the wierdest thing Ive ever seen.
    PHP Code:
    mssql_query($sql) or die('error inserting into DB'
    When this page is executed, it returns "error inserting into DB". But..... The query is still executed and the record is inserted into the DB.

    Ive read up on mssql_query(), but Im still trying to understand how both the query and the error can be executed.

    Any help?

    PHP version: 5.0.2
    MSsql: latest version, and all patches

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    (Never encountered that problem myself.)
    _________

    Right now you're only returning your custom error message (which doesn't say a lot).

    Try to alter the 'die' message to:

    mysql_query($sql) or die ("Error msg: ".mysql_error());

    Then MySQL will return a message specifying what went wrong in clear text.

    If you want the numeric value for the error message, you can use:

    mysql_query($sql) or die (mysql_errno().": ".mysql_error());
    (To establish good habits, you should use your connection handle as argument for the error message:
    $con=mysql_connect($host, $user, $password);
    then later in code:
    mysql_errno($con) and mysql_error($con). This is required when working with PHP 5.x
    )


    You can find what the different numeric error codes means here:
    http://dev.mysql.com/doc/mysql/en/error-handling.html
    S. Rosland

  4. #3
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Thanks for the help Rosland, but Im not using MYsql, im using MSsql. Do you know of any error message functions that I can use in MSsql. It doesnt seem that mssql_error() exists....

  5. #4
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    It seems to be a bug in PHP, mssql_query();

    http://aspn.activestate.com/ASPN/Mai...php-Dev/489684

  6. #5
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Aaah..

    Sorry, I missed that.

    I always assume that DB questions here are MySQL (as the forum is called PHP and MySQL)

    You are of course right in posting here if you consider it more of a PHP question than a SQL question (as it appears to be)

    If it's leaning more towards MSSQL, I would post it in the ASP/ASP.net and Microsoft SQL forum. There might be some MS SQL experts there who never read posts here.

    I've never used MSSQL. Does it not contain any sort of error reporting functions? (Even though there were none here, it's a nice feature to have)

    EDIT:
    I just saw you asked me the same question. I don't know. I'll see what I can find out.
    S. Rosland

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Just found this user note in the online PHP manual:
    Warning ! with php 4.3.10, when you use mssql_query to insert or update data, the returned result is false but the query is really executed.

    Solution -> Download the ms sql extension patched from:
    http://sourceforge.net/project/showf...group_id=75482

    PHP 4.3.10
    http://no2.php.net/manual/en/function.mssql-query.php
    S. Rosland


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
  •  

Search tags for this page

mssql query result returning false on insert

Click on a term to search for related topics.
All times are GMT -6. The time now is 09:25 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com