Jump to content

premiso

Members
  • Posts

    6,951
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by premiso

  1. One question:

    In your my_query function you set display_errors to 1 in the beginning and then reset it to 0 only if there is an error. Should I reset it to 0 even when there is not an error?

     

    Basically, you do not want a production system to show errors to everyone. I am not sure how it was setup prior to, but you can use the ini_get to get the value of it and re-set it to that after the script runs. But it does need to be 1 for the error to be caught by the output buffer.

  2. When I think laptop, I think portable computing and the rig you posted stinks for that. 3-4 hours of battery life isn't enough for me (and there's NO way you'll get that while gaming)

     

    If you need to save space, and don't mind staying plugged-in, it's great.

     

    Or you just need to be around family (having kids) and not wanting to be limited to you range of a desk or having the desk in the entertainment room, sure. :)

     

    And NO YOU ARE WRONG.

  3. The messages coming from the first set were from the php function returning a warning to throw up a bigger error. It seems that it is how the MSSQL driver is coded. Looking at the mssql functions page: http://jm2.php.net/manual/en/function.mssql-get-last-message.php#12352 there is a code using output buffers (a hack imo) to catch the error and parse it to display prettier.

     

    Here is an updated version of that you can try and see if it fits your needs:

     

    function treat_mssql_error($buffer) { 
        $buffer=preg_replace("#<br>\n<b>Warning</b>:  MS SQL message:#i","<b>Error in query (SQL Server)</b>: ",$buffer); 
        $buffer=explode("(severity",$buffer); 
        return $buffer[0]; 
    } 
    
    function my_query($query,$cnx, &$sql_error="") { 
        ob_start(); 
        ini_set('display_errors', '1'); // you may want to check if this was enabled prior but yea.
        $result=mssql_query($query,$cnx); 
        if(!$result) { 
            $sql_error=treat_mssql_error(ob_get_contents()); 
            ob_end_clean(); 
            ini_set('display_errors', '0');
            return false; 
        } 
    
        ob_end_clean(); 
        return true; 
    } 

     

    You can expand this in many ways, such as using it in a class wrapper instead of a function etc, but that is the gist.

     

    Alternative, you can check and see if PDO will work for your needs, as I think it would handle the errors a bit cleaner...if it has MSSQL Server support.

  4. But I can not find the variable $mode.  I have done a complete site search for the variable $mode and can't locate a thing.

     

    So i'm confused how the previous developer wrote this and how these variables are defined.

     

    He probably wrote it with register_globals turned on, which is a security risk and has been defaulted to off since php 4. Basically that takes GET / SESSION / POST / COOKIE data and converts it to a variable, so $mode was probably inside one of those. To fix it, you just need to figure out where it was coming from and do something like: 

     

    if ($_GET['mode'] == "new")

  5. Not knowing much else of your code, this is how it would need to be done, as shown by kicken

     

    $sql = "INSERT INTO info_cats (cat_id, info_id) VALUES (" . join(',', $values) . ") ON DUPLICATE KEY UPDATE cat_id = $values[0], info_id = $values[1]";
    

     

    If you want something different, you will need to elaborate more on what you are looking for and possibly show more code.

  6. Another fun typo from my past:

    cd /usr/local/apache/web3
    sudo chmod -R 744 /

    That took out an entire server permanently, it had to be wiped and restored.

     

    That is why I tend to use dots more often than slashes after I cd to a directory :)

  7. Are you sure you do not want to group by the category?

     

    $query = "SELECT * FROM gift_db2 LEFT OUTER JOIN student_db ON gift_db2.category = student_db.name GROUP BY  gift_db2.category ORDER BY gift_db2.grade DESC";

     

    Not knowing how it is not displaying right, just a shot in the dark.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.