note 84950 added to function.mysql-query

From: Date: Wed, 06 Aug 2008 23:20:31 +0000
Subject: note 84950 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-143258@lists.php.net to get a copy of this message
Clarification to masteracc0 at aol dot com's earlier note: <?php // from masteracc0 $result1 = mysql_query($query1); $result2 = mysql_query($query2); //$result1 IS NOT EQUAL TO $result2 but will not provide an error //but printing these queries to the screen will provide the same result echo($result1); echo($result2); ?> $result1 and $result2 are different not because of the null string terminator but because they are not the results of the queries. They are resource handles to the results of (functionally identical, though this is irrelevant) queries run at different times. So there will be no error as long as the query is valid. The actual result of the query will be the same regardless of the null string: <?php // substitute your own simple query $testquery = "SELECT name FROM days WHERE uid=1"; $withnull = $testquery . "\0"; $result1 = mysql_query($testquery); $result2 = mysql_query($withnull); $result3 = mysql_query($testquery); echo($result1); echo("<br />" . $result2); echo("<br />" . $result3); echo ("<br /> \$result1 and \$result2 equal?"); echo $result1 == $result2 ? "yes!" : "no"; echo ("<br /> \$result1 and \$result3 equal?"); echo $result1 == $result3 ? "yes!" : "no"; $testresult1 = mysql_fetch_assoc($result1); $testresult2 = mysql_fetch_assoc($result2); $testresult3 = mysql_fetch_assoc($result3); echo ("<br /> \$testresult1 and \$testresult2 equal? "); echo $testresult1 == $testresult2 ? "yes!" : "no"; echo ("<br /> \$testresult1 and \$testresult3 equal? "); echo $testresult1 == $testresult3 ? "yes!" : "no"; ?> You can see in none of these cases does the null character change the equality. Results 1 and 3 come from the same query and the comparisons are the same as the comparison of results 1 and 2. The resource handles are different, the results are the same. This means you need not fear the null character. Just understand that a new resource handle is created every time you call mysql_query(). ---- Server IP: 208.69.120.35 Probable Submitter: 63.150.8.10 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/84950 Del: integrated -- https://master.php.net/note/delete/84950/integrated Del: useless -- https://master.php.net/note/delete/84950/useless Del: bad code -- https://master.php.net/note/delete/84950/bad+code Del: spam -- https://master.php.net/note/delete/84950/spam Del: non-english -- https://master.php.net/note/delete/84950/non-english Del: in docs -- https://master.php.net/note/delete/84950/in+docs Del: other reasons-- https://master.php.net/note/delete/84950 Reject -- https://master.php.net/note/reject/84950 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143258) next »