www.webdeveloper.com
Results 1 to 13 of 13

Thread: Some Errors is ignored PHP or Apache

  1. #1
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240

    Some Errors is ignored PHP or Apache

    If this should be under PHP or Server Management I don't know, so I post it here.

    To day I discovered something that I tested some more. Either my PHP or my Apache Settings are set wrong somewhere.

    I used the fallowing two test functions.
    PHP Code:
    function queryTest1($objConn) {
        
    $tmpQuery mysqli_query($objConn"SELECT * FROM testTable");

        if(
    mysqli_num_rows($objResult) < 1) return false;
        else return 
    true;
    }

    function 
    queryTest2($objConn) {
        if(!
    mysqli_query($objConn"INSERT INTO testTable (cTekst) VALUES ('test')")) {
            echo 
    mysqli_error($objConn);
            return 
    false;

        }else return 
    true

    My testTable contains only two columns "cTekst" and "cDate".
    In the first test function I should be getting this error
    Undefined variable: objResult
    The second test function should give me this error
    Field 'cDate' doesn't have a default value
    But no.
    The first just ignores the error, and returns true.
    The second just inserts "test" and gives the cDate the value 0000-00-00.

    My external rental server works as it should, but not my home testing server. Anyone know what this could be?

    My home server runs:
    Ubuntu Server 9.10
    Apache 2.2.12
    PHP 5.3.0
    MySQL 5.1

    When I make mistakes I expect my server to complain about it and not just go along with it.

    And yes, Error messaging is activated and set to display all errors, warnings etc. and it usually works, just not with these two error types apparently.

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    What exactly do you have in your php.ini as a value for display_errors? The first would be a notice level error so E_ALL should cover it I'd have thought. The second one I wouldn't necessarily expect an error unless the column has the NOT NULL flag set.

  3. #3
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    This is all the error related settins from my php.ini
    Code:
    error_reporting = E_ALL | E_STRICT
    display_errors = On
    display_startup_errors = On
    ignore_repeated_errors = Off
    ignore_repeated_source = Off
    report_memleaks = On
    track_errors = On
    And about the NOT NULL.
    This is my cDate export
    Code:
    'cDate' date NOT NULL

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    ...The second just inserts "test" and gives the cDate the value 0000-00-00....
    That would be strictly a MySQL issue -- nothing to do directly with PHP. It would seem to imply that on that test platform that cDate is not specified NOT NULL in the table definition.

    I realize that does not fix anything for you, but it makes me wonder if there is some disconnect here, such as editing the wrong include file or something (e.g. in a different directory from the one that is actually being included)? (Not that I would ever have done something like that. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    As to the nulls thing, my understanding of it is if you don't define the value in the insert, MySQL considers this an implicit NULL and will use the default value. If no default value is set MySQL defines one internally based on the column type.

    I tested on my own table doing what you did, it inserted without complaining with a date field set to not allow null and either a default value set or not.

    -jim

  6. #6
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    but it makes me wonder if there is some disconnect here, such as editing the wrong include file or something (e.g. in a different directory from the one that is actually being included)?
    Do you mean that I update the wrong table?
    That would be possible, except that what I insert appears in the correct table

    And according to phpmyadmin's structure output, the cDate column should be specified NOT NULL.

    As to the nulls thing, my understanding of it is if you don't define the value in the insert, MySQL considers this an implicit NULL and will use the default value. If no default value is set MySQL defines one internally based on the column type.

    I tested on my own table doing what you did, it inserted without complaining with a date field set to not allow null and either a default value set or not.
    I don't know how the correct way for MySQL to behave is, and actually I don't care if it should or should not generate an error in this example. What I do care about however, is that when I test my things on my server, I can be sure that it will work on others to.

    I think it's suck pretty much to use hours on testing, and then have my work generate errors on other servers because my setup did not care about the mistakes I made. The point of testing is to correct possible mistakes. But that's not easy if the mistakes is ignored :S
    Last edited by dk_zero-cool; 01-28-2010 at 03:25 PM.

  7. #7
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    Is your sandbox MySQL the exact same version and platform as on your production server?

    If not, you might have found an issue between two versions or platforms in this specific testing scenario. Also, most importantly, not all SQL servers are the same, i.e. some interpret the null as implicit in the insert situation, others explicitly (when a null really is a null). MySQL is not ANSI SQL through and through, either.

    Your pain is understood, just trying to get to the bottom of this.

    -jim
    Last edited by SrWebDeveloper; 01-28-2010 at 03:29 PM. Reason: added link

  8. #8
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    Is your sandbox MySQL the exact same version and platform as on your production server?
    Hmm, no.
    Mine is: 5.1.37
    The other is: 5.1.42-community

    MySQL is not ANSI SQL through and through if you follow what I'm saying.
    Sure

    But what about the PHP error.
    I think that we can agree that trying to use an undefined variable in an mysqli_num_rows function would produce one of two errors. Either an undefined variable error or an error for trying to use the mysqli_num_rows function without any result link?

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Quote Originally Posted by dk_zero-cool View Post
    Do you mean that I update the wrong table?
    No, I was just speculating whether the PHP file that was being executed (e.g. included) was not the one you were editing. It happened to me once, and I spent maybe an hour of wasted time before I realized it.

    I'm guessing it's more likely though, from the combination of problems, is that there is some version and/or configuration difference(s), but I thought it was worth double-checking before you start digging into config files, installing new versions, etc. (though ultimately it is desirable to have your test bed be as close to the production environment as possible, other than having display_errors turned on on the test bed, perhaps).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    (though ultimately it is desirable to have your test bed be as close to the production environment as possible, other than having display_errors turned on on the test bed, perhaps).
    I think a test bed should be as strict as possible to be as sure that production environments will not encounter any problems.

    Turning errors off on a test machine would not be a good idea.

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    No, I was saying to have display_errors turned on on the test/development machine, while you will likely want it turned off on the production version. (At least that's what I was trying to say.) Setting the error_reporting level to as strict as you want it on the test host, as you point out, is a good idea, too.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    Ok, I removed everything (Apache, PHP), installed it again and configured the httpd.conf and php.ini from scratch.

    Now I get this wonderfull message.
    Undefined variable: objResult
    So I guess it's fixed.
    unfortunately without any answers to the problem though.

    Either it was one of the old conf files, or PHP 5.3.0 (Updated to 5.3.1)

  13. #13
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    I haven't updated locally to PHP 5.3.x yet, as nothing I've been working on has been later than 5.2.x.

    Anyway, wish I could tell you what the original problem was, but I'm glad you got it fixed, hopefully.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles