php - different number of results in SQL Statement when using die() -


in php script mysql request $sql hardcoded sql-select statement:

$result = mysqli_query($server,$sql); echo '<br>'.$sql.'*'.mysqli_num_rows($result); #die('test'); 

the whole script quite complex running code above prints sql-statement , delivers 14 result rows. wanted check database directly @ point added above die() after request. doing sql-satement delivering 13 result rows.

i know cutting code after execution may change state of system probable database operations in cut off code won't come effect anymore. no matter if in run before die() has been active or not 14 results without die() , 13 results die().

so problem is: everytime when run code without die() , , directly afterwards run code again die() activated until die() statement there no obvious difference in code or state of database select statement should deliver same number of rows... doesn't.

can think of setting makes behavior understandable? hope explanation not wierd - otherwise happy answer questions. there simple explanation seem miss...

edit:

the problem have bug have hidden in large piece of code. surely hard answer if have not got full code. maybe helps if reformulate question following task:

can program php code including above snippet shows same behavior - after each run (activated or not) delivers 14 results die() deactivated , 13 runs die() activated? - of course allowing sourcecode analyze cheating...

edit 2:

i found reason of error. because printing of php notices , warning in code accumulated during development , in firefox seem lead problem if reach size before <head> section. die() case causes less of these because breaks earlier , in fact doesn't reach <head>. if mute notices both examples behave same. lead error haven't examined... sorry did not hint error reporting in describing question, had no clue that might reason - active in both cases....

not answer, example of mean "simple, self-contained (,correct) example".

<?php $server = setup(); $sql = 'select id,x,y,z sofoo'; $result = mysqli_query($server,$sql); echo '<br>'.$sql.'*'.mysqli_num_rows($result); #die('test');  function setup() {     $server = new mysqli('localhost', 'localonly', 'localonly', 'test');     if ( $server->connect_errno ) {         die('!'.$server->connect_error);     }      $server->query('create temporary table sofoo (             id int auto_increment,             x char(255),             y char(255),             z char(255),             primary key(id)          )     ') or die('!'.$server->error);      $stmt=$server->prepare('insert sofoo (x,y,z) values (?,?,?)')         or die('!'.$server->error);      $stmt->bind_param('sss', $x, $y, $z) or die('!'.$stmt->error);     foreach( range('a','n') $x) { // fill in 14 records         $z = $y = $x;         $stmt->execute() or die('!'.$stmt->error);     }     return $server; } 

you have copy&paste it, adjust mysql connection data (credentials, host, database) , run it.

in case prints <br>select id,x,y,z sofoo*14 expected (since setup() function added 14 records temporary table) regardless of whether die() there or not. example doesn't behave description, yet contains information (and code snippet) you've provided. must different on side.
i've tested script php5.6.10 (win32) , mysql 5.6.22-log (win32).


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -