|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
<? 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; } ?><? 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; } } ?><?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 !"; ?>