diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c45d5563a95..f65a80dee9d 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -883,10 +883,14 @@ PHP_FUNCTION(pg_result) RETURN_FALSE; } - return_value->value.str.val = PQgetvalue(pgsql_result, Z_LVAL_PP(row), field_offset); - return_value->value.str.len = (return_value->value.str.val ? strlen(return_value->value.str.val) : 0); - return_value->value.str.val = safe_estrndup(return_value->value.str.val,return_value->value.str.len); - return_value->type = IS_STRING; + if (PQgetisnull(pgsql_result, Z_LVAL_PP(row), field_offset)) { + return_value->type = IS_NULL; + } else { + return_value->value.str.val = PQgetvalue(pgsql_result, Z_LVAL_PP(row), field_offset); + return_value->value.str.len = (return_value->value.str.val ? strlen(return_value->value.str.val) : 0); + return_value->value.str.val = safe_estrndup(return_value->value.str.val,return_value->value.str.len); + return_value->type = IS_STRING; + } } /* }}} */ @@ -933,33 +937,39 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) } array_init(return_value); for (i = 0, num_fields = PQnfields(pgsql_result); i