Re: cvs: php4 /ext/pgsql pgsql.c
| From: | Yasuo Ohgaki | Date: | Sat, 24 Aug 2002 23:53:05 +0000 |
| Subject: | Re: cvs: php4 /ext/pgsql pgsql.c | ||
| References: | 1 2 3 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-13652@lists.php.net to get a copy of this message | ||
The example was completely useless.
Shouldn't write anything early Sunday morning :)
Here is better one.
/** NEW WAY **/
$db = pg_connect($connstr);
if (pg_connection_status($db) != PGSQL_CONNECTIN_OK)) {
// error
return FALSE;
}
// do something useful
/** OLD WAY **/
$db = pg_connect($connstr);
if (!is_resource($db)) {
// error
return FALSE;
}
if (pg_connection_status($db) != PGSQL_CONNECTIN_OK)) {
// error
return FALSE;
}
// do something useful
We had to check if resource parameter w/o this patch.
Error message is not needed for these.
--
Yasuo Ohgaki
Yasuo Ohgaki wrote:
derick@php.net wrote:On Sat, 24 Aug 2002, Yasuo Ohgaki wrote:I usually write code as follows $result = pg_get_result($db); if (!is_resource($result)) { // error return FALSE; } if (($error = pg_get_result($db)) { // error return FALSE; } // do something useful A person mentioned we can write if (!($result = pg_get_result($db))) { // error return FALSE; } if these functions do not raise E_WARNING. These functions takes resource as parameter and functions returns resource may return FALSE when there is error, resulting E_WARNING since parameter expected is resource, but bool is passed. (I know we can use @, but error event causes problem with user defiend error handlers if error is raised.) We can simpliy script a bit with this change. IMO, it's a little easier to read and it does not hide bugs badly. Users will catch script bugs when they get resource almost always, so we can safely remove error message. Although, I cannot think of case this change hide script bugs badly, I'm willing to revert this if this hide bugs. Any comments? -- Yasuo OhgakiWhy would you want that? Derickyohgaki Sat Aug 24 18:28:28 2002 EDTModified files: /php4/ext/pgsql pgsql.c Log: Changed pg_connection_info()/pg_connection_reset()/pg_connection_busy()/pg_result_status()/pg_result_error() silently return FALSE when resource is not passed to them. @ Changed pg_connection_info()/pg_connection_reset()/pg_connection_busy()/pg_result_status()/pg_result_error() silently return FALSE when resource is not passed to them. (Yasuo)