php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65411 die() don't terminate the current script if mysqli::query use MYSQLI_USE_RESULT
Submitted: 2013-08-07 08:55 UTC Modified: 2013-08-07 14:36 UTC
From: tecdoc at ukr dot net Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: Irrelevant OS: Windows 7 32bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tecdoc at ukr dot net
New email:
PHP Version: OS:

 

 [2013-08-07 08:55 UTC] tecdoc at ukr dot net
Description:
------------
Tested on PHP version is 5.4.16 and 5.3.13

die() don't terminate the current script when mysqli::query use MYSQLI_USE_RESULT

---
From manual page: http://www.php.net/mysqli.query#refsect1-mysqli.query-seealso
---

Test script:
---------------
$mysqli = new mysqli('localhost', 'root', '', 'db1');
if (!$mysqli->set_charset("utf8"))
    die('Set Charset Error: ' . $mysqli->error);

// tab - it is a table that have more than 3 000 000 rows
$q = "SELECT * FROM tab1";

// open query and try close all
$result = $mysqli->query($q, MYSQLI_USE_RESULT);
$result->free();
$mysqli->close();
die('why don't terminated script?');

// this end of script don't terminate also
$result = $mysqli->query($q, MYSQLI_USE_RESULT);
$result->free();
$thread = $mysqli->thread_id;
$mysqli->kill($thread);
$mysqli->close();
die('why don't terminated script?');



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-07 10:04 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-08-07 10:04 UTC] johannes@php.net
After fixing the error and escaping the ' in the die call 
   die('why don\'t terminated script?');
the script works as expected. I don't now what effect you see as "not terminating"
 [2013-08-07 11:59 UTC] tecdoc at ukr dot net
because you do script on table with small count of rows
do you try did script when table have more than 3 000 000 rows?
 [2013-08-07 14:27 UTC] johannes@php.net
Why do you request lots of data if you don't use it?
 [2013-08-07 14:36 UTC] tecdoc at ukr dot net
I use this script.
I do export data from this big table in php. when export is doing i check some data and if this have some mistake it is need do die().

But i will find this bug. What problem abut how i use it

It is whole script
---------------------
<?php
$mysqli = new mysqli('localhost', 'root', '', 'db1');

if ($mysqli->connect_error) 
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);

//Принудительная установка запросов и ответов БД в кодировку utf8
if (!$mysqli->set_charset("utf8"))
    die('Set Charset Error: ' . $mysqli->error);

set_time_limit(0);	
	
//
// ну собсвенно получаем данные
$q = "SELECT * FROM tab1";
$result = $mysqli->query($q, MYSQLI_USE_RESULT);


//
// разбераем результат
$fp_csv = fopen("d:\\result\\nums-replace.csv", 'w');
$is_first = true;	// флаг - первый заход на разбор
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
	$row['text'] = iconv("utf-8", "windows-1251", $row['text']); //кодировка
	if(!empty($row['datum'])) $row['datum'] = str_pad($row['entfalldatum'],8,'0'); //дата
	
	// запишем название колонок
	if($is_first){
		fputcsv($fp_csv, array_keys($row), ";");
		$is_first = false;
	}

	//check field
	if(empty($row['index']))
		// !!!!!!!!!!!!!!!!!!!!!!
		die(); // DON'T TERMINATE

	fputcsv($fp_csv, $row, ";");
}
fclose($fp_csv);

/* free result set */
$result->free();

/* close connection */
$mysqli->close();
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC