php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37925 After a try catch block, the echo doens't work with an exit
Submitted: 2006-06-27 11:05 UTC Modified: 2006-06-30 11:28 UTC
From: batataw at gmail dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.1.4 OS: Linux Fedora
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: batataw at gmail dot com
New email:
PHP Version: OS:

 

 [2006-06-27 11:05 UTC] batataw at gmail dot com
Description:
------------
After a Try/Catch block I used an exit. It's impossible to display all the echos (print, var_dump...) between the Try/Catch block and the exit.
I had to use these functions to force the echo :
$buffer = ob_get_flush();//hack
flush();	   
exit;

Reproduce code:
---------------
//Execute Request
try{
  $sth->execute();
}
catch(PDOException $e){
  $errmsg = implode(":",$sth->errorInfo());
   Error::userErrorHandler(E_USER_WARNING, 'DB Error : '.    $errmsg, __FILE__, __LINE__, $errmsg);
}
------------------------------------		
echo "Message Error";
exit;

Expected result:
----------------
Message Error

Actual result:
--------------
Nothing

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-27 11:14 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-06-27 11:18 UTC] batataw at gmail dot com
<?
try{
  $sth->execute();
}
catch(PDOException $e){
  $errmsg = implode(":",$sth->errorInfo());
   Error::userErrorHandler(E_USER_WARNING, 'DB Error : '.    $errmsg,
__FILE__, __LINE__, $errmsg);
echo "Message Error";
exit;
}
?>
 [2006-06-27 11:25 UTC] tony2001@php.net
I don't think I have $sth and Error::userErrorHandler() method. That's why I asked for short but COMPLETE reproduce script.
 [2006-06-27 11:30 UTC] batataw at gmail dot com
<?
public function insertUser($user){		    	    		
		
	//call the stored procedure
		$sql = "CALL user_insert(@userId,:username,:passwd,:firstname,:lastname,:email,:web,:country,:language,:gender,:city,:dob,:initial,:avatar,:servicelevelId);";
				
		//Prepare request
		try{
			$sth = $this->db->prepare($sql);
		}
		catch(PDOException $e){				
			$errmsg = implode(":",$sth->errorInfo());
			Error::userErrorHandler(E_USER_WARNING, $errmsg, __FILE__, __LINE__, DRM_ERROR_DB_CALL);						
		}
		$sth->bindParam(":username",	$user["username"],PDO::PARAM_STR);
		$sth->bindParam(":passwd",		$user["passwd"],PDO::PARAM_STR);
		$sth->bindParam(":firstname",	$user["firstname"],PDO::PARAM_STR);
		$sth->bindParam(":lastname",	$user["lastname"],PDO::PARAM_STR);

//Execute Request
		try{
			$sth->execute();
		}
		catch(PDOException $e){
					
			$errmsg = implode(":",$sth->errorInfo());
			Error::userErrorHandler(E_USER_WARNING, 'DB Error : '. $errmsg, __FILE__, __LINE__, $errmsg);				echo "Error Message";
exit;		
		}		

}
?>
 [2006-06-27 11:52 UTC] bjori@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2006-06-27 11:53 UTC] tony2001@php.net
Please provide SHORT AND COMPLETE reproduce script, which I can copy/paste and run to reproduce your problem.
Until then -> bogus.
 [2006-06-30 10:56 UTC] batataw at gmail dot com
<?php

		define ('DRM_DMDB_DEV',  'dev');

		$GLOBALS[DRM_DMDB_DEV]['db_dsn'] 		= "mysql:dbname=mydatabase;host=localhost";
		$GLOBALS[DRM_DMDB_DEV]['db_user']		= "root";
		$GLOBALS[DRM_DMDB_DEV]['db_passwd']		= "";
		
		$conf = DRM_DMDB_DEV;


	   	try{
			$db = new PDO($GLOBALS[$conf]['db_dsn'], $GLOBALS[$conf]['db_user'], $GLOBALS[$conf]['db_passwd']);
			$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);			
		}
		catch(PDOException $e){			
			$errmsg = "connection failed: ".$e->getMessage();
			echo $errmsg;
			exit;
		}	

    	    	
    	    	
		//call the stored procedure
		$sql = "CALL user_insert(@userId,:username,:passwd);";
				
		//Prepare request
		try{
			$sth = $db->prepare($sql);
		}
		catch(PDOException $e){				
			$errmsg = implode(":",$sth->errorInfo());
			Error::userErrorHandler(E_USER_WARNING, $errmsg, __FILE__, __LINE__, DRM_ERROR_DB_CALL);						
		}
		
		
		$sth->bindParam(":username",	$user["username"],PDO::PARAM_STR);
		$sth->bindParam(":passwd",		$user["passwd"],PDO::PARAM_STR);
																							
		//Execute Request
		try{
			$sth->execute();
		}
		catch(PDOException $e){
					
			$errmsg = implode(":",$sth->errorInfo());
			echo $errmsg;
			exit; 						
		}		
		
		
		echo "OK !";
		

?>
 [2006-06-30 11:06 UTC] tony2001@php.net
42000:1305:PROCEDURE test.user_insert does not exist
 [2006-06-30 11:18 UTC] batataw at gmail dot com
Below, the store procedure.

BEGIN
	#declare local variables
	DECLARE sp_userId BIGINT(30) DEFAULT 0;

	#declare copies of incoming variables
	DECLARE sp_username VARCHAR(30);
	DECLARE sp_passwd VARCHAR(20);


	#tidy input and apply initial transformations
	SET sp_username = TRIM(in_username);
	SET sp_passwd = TRIM(in_passwd);

	#the insert
	INSERT INTO user
	(username, passwd)
	VALUES
	(sp_username, sp_passwd);

	#get the new userId
	SELECT LAST_INSERT_ID() INTO sp_userId;

	#set the output variable
	SET out_userId = sp_userId;
END
 [2006-06-30 11:28 UTC] tony2001@php.net
I don't have your database and your tables, including "user" table. Please provide COMPLETE reproduce script that doesn't require any nonexistent tables, database and stored procedures.
You can create them in the script itself, btw.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC