RETURN_FALSE;
}
/* ensure that the link did not die */
- if (PGG(auto_reset_persistent)) {
+ if (PGG(auto_reset_persistent) & 1) {
/* need to send & get something from backend to
make sure we catch CONNECTION_BAD everytime */
PGresult *pg_result;
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first.");
}
pgsql_result = PQexec(pgsql, Z_STRVAL_PP(query));
-
+ if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
+ PQclear(pgsql_result);
+ PQreset(pgsql);
+ pgsql_result = PQexec(pgsql, Z_STRVAL_PP(query));
+ }
+
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
pg_result = (pgsql_result_handle *) emalloc(sizeof(pgsql_result_handle));
pg_result->conn = pgsql;
pg_result->result = pgsql_result;
- pg_result->row = -1;
+ pg_result->row = 0;
ZEND_REGISTER_RESOURCE(return_value, pg_result, le_result);
} else {
RETURN_FALSE;
pgsql_result = pg_result->result;
if (ZEND_NUM_ARGS() == 1) {
- pg_result->row++;
pgsql_row = pg_result->row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
RETURN_FALSE;
}
+ pg_result->row++;
} else {
if (Z_TYPE_PP(row) != IS_NULL) {
convert_to_long_ex(row);
}
} else {
/* If 2nd param is NULL, use internal row counter to access next row */
- pg_result->row++;
pgsql_row = pg_result->row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
RETURN_FALSE;
}
+ pg_result->row++;
}
}
array_init(return_value);
}
/* seek to offset */
- pg_result->row = row - 1;
+ pg_result->row = row;
RETURN_TRUE;
}
/* }}} */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "There are results on this connection. Call pg_get_result() until it returns FALSE.");
}
if (!PQsendQuery(pgsql, query)) {
- RETURN_FALSE;
+ if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
+ PQreset(pgsql);
+ }
+ if (!PQsendQuery(pgsql, query)) {
+ RETURN_FALSE;
+ }
}
if (PQ_SETNONBLOCKING(pgsql, 0)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode.");