Php Postgres Get Error
Contents |
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes php pg_query error handling Context options and parameters Supported Protocols and Wrappers Security
Pg_result_error_field
Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security pg_connect error 500 Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with
Pg Error
PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions postgres last error Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box pg_last_notice » « pg_insert PHP Manual Function Reference Database Extensions Vendor Specific Database Extensions PostgreSQL PostgreSQL Functions Change language: English Brazilian Portuguese Chinese (Si
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Pg_connect Or Die
of this site About Us Learn more about Stack Overflow the company
Pg Connect Error
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges pg_send_query Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a http://php.net/manual/en/function.pg-last-error.php minute: Sign up catching errors from Postgresql to PHP up vote 3 down vote favorite 1 I want to catch and show the error(in a way that i choose) of a query on the web page using php . So instead of the code below $result=pg_query($connection,$query); if($result){ //success } else{ echo pg_last_error($connection); } can i use a method like error code matching http://stackoverflow.com/questions/12349230/catching-errors-from-postgresql-to-php or something else to achieve things like if(error equals duplicate value error){ echo "this value already exists"; } else if(error equals different type error){ echo "You should enter wrong type for column blabla" } Note I am using postgresql php sql postgresql error-handling share|improve this question edited Sep 10 '12 at 10:32 asked Sep 10 '12 at 9:52 woryzower 4741716 Yes, you can do this, but I'm not sure what you are asking. –Aleks G Sep 10 '12 at 9:57 @AleksG I don't want to use pg_last_error function . I want to write error message manually for corresponding error –woryzower Sep 10 '12 at 10:03 add a comment| 3 Answers 3 active oldest votes up vote 6 down vote accepted It's possible to retrieve the desirable standard SQLSTATE errcode, but there's a trick: the query has to be sent through the asynchronous pg_send_query() instead of the synchronous pg_query(). This is because pg_query() returns false on error instead of the resource that is required to peek at the error details. When pg_get_result() is called after pg_send_query, it will block anyway until
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us http://stackoverflow.com/questions/3229388/catch-postgres-error-in-php Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up catch postgres error in PHP up vote connect error 0 down vote favorite 1 I have table in postgressql with primare key (pk_user). If i insert wrong parametrs. postgres call exception:( ERROR: duplicate key value violates unique constraint "pk_user" ) this is ok, but i like catch this error and transform it to user interface ( this username is used) my php script: $sql="INSERT INTO user (....) VALUES (....)" @$result=pg_query($dbconn,$sql); if(!$result) { $error= pg_last_error($dbconn); if($error==='ERROR: duplicate php postgres get key value violates unique constraint "pk_user"') $outputmesage="this username is used"; .... } else { ..... } but construction if($error==='ERROR: duplicate key value violates unique constraint "pk_user"') is wrong. I don know what write this. Function strcmp(str1,str2) is wrong too. P.s: I'm sorry for my bad english php postgresql share|improve this question asked Jul 12 '10 at 14:27 Torenaga 1513 My comment is a bit irrelevant, but shouldn't you first check if user name is already used and then try to insert it? I do not like (maybe it's personal) the approach of doing something that I know it might be wrong and the see from the side-effects the cause. –dimitris mistriotis Jul 12 '10 at 15:51 1 dimitris mistriotis: No, this is the wrong way. Even if you check it first, you have no guarantee someone will not ask for the same username just between your check and insert (unless in a transaction - but that restricts concurrency and is needless there as just a single query suffices). Apart from the correctness of Torenaga's approach, it is also more effective, because it always needs just a single query, whereas you make two queries most of the