From ce7fe210cb68ccef8adb1cbd509ccde0c792c8b3 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 6 Jan 2021 04:03:25 +0000 Subject: [PATCH] Deprecate using the implicit default PgSQL connection The DB connection should be provided in all cases as the first argument. The overloaded function signatures will be removed in the future. Warn about this change. Part of https://wiki.php.net/rfc/deprecations_php_8_1. --- UPGRADING | 3 + ext/pgsql/pgsql.c | 11 +- ext/pgsql/tests/01createdb.phpt | 2 +- ext/pgsql/tests/05large_object.phpt | 10 +- ext/pgsql/tests/07optional.phpt | 6 +- ext/pgsql/tests/08escape.phpt | 13 +- ext/pgsql/tests/09notice.phpt | 4 +- ext/pgsql/tests/13pg_select_9.phpt | 2 +- ext/pgsql/tests/18pg_escape_bytea_before.phpt | 3 +- ext/pgsql/tests/18pg_escape_bytea_esc.phpt | 2 +- ext/pgsql/tests/18pg_escape_bytea_hex.phpt | 2 +- ext/pgsql/tests/27large_object_oid.phpt | 10 +- .../tests/28large_object_import_oid.phpt | 14 +- ext/pgsql/tests/80_bug24499.phpt | 8 +- ext/pgsql/tests/80_bug27597.phpt | 8 +- ext/pgsql/tests/80_bug32223.phpt | 4 +- ext/pgsql/tests/80_bug32223b.phpt | 4 +- ext/pgsql/tests/80_bug39971.phpt | 2 +- ext/pgsql/tests/80_bug42783.phpt | 4 +- ext/pgsql/tests/98old_api.phpt | 8 +- ext/pgsql/tests/bug37100_9.phpt | 12 +- ext/pgsql/tests/bug46408.phpt | 2 +- ext/pgsql/tests/bug47199.phpt | 10 +- ext/pgsql/tests/bug60244.phpt | 2 +- ext/pgsql/tests/bug64609.phpt | 8 +- ext/pgsql/tests/bug65119.phpt | 6 +- ext/pgsql/tests/bug68638.phpt | 6 +- ext/pgsql/tests/bug71998.phpt | 2 +- ext/pgsql/tests/bug72028.phpt | 6 +- ext/pgsql/tests/bug72197.phpt | 2 + ext/pgsql/tests/bug75419.phpt | 3 +- ext/pgsql/tests/close_default_link.phpt | 3 +- ext/pgsql/tests/connect_after_close.phpt | 5 +- .../deprecated_implicit_default_link.phpt | 144 ++++++++++++++++++ ext/pgsql/tests/lcmess.inc | 10 +- ext/pgsql/tests/no_link_open.phpt | 3 +- ext/pgsql/tests/pg_delete_001.phpt | 16 +- ext/pgsql/tests/pg_insert_001.phpt | 8 +- ext/pgsql/tests/pg_meta_data_001.phpt | 12 +- ext/pgsql/tests/pg_select_001.phpt | 22 +-- ext/pgsql/tests/pg_update_001.phpt | 14 +- ext/pgsql/tests/skipif.inc | 10 +- 42 files changed, 311 insertions(+), 115 deletions(-) create mode 100644 ext/pgsql/tests/deprecated_implicit_default_link.phpt diff --git a/UPGRADING b/UPGRADING index b5317605d175d..f5929d75fe73d 100644 --- a/UPGRADING +++ b/UPGRADING @@ -143,6 +143,9 @@ PHP 8.1 UPGRADE NOTES . The PgSQL functions now accept and return, respectively, \PgSql\Lob objects instead of "pgsql large object" resources. Return value checks using is_resource() should be replaced with checks for `false`. + . Not passing the connection argument to PgSQL functions and using the + default connection is deprecated. + RFC: https://wiki.php.net/rfc/deprecations_php_8_1 - PSpell: . The PSpell functions now accept and return, respectively, PSpell\Dictionary objects diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index a992b331631ce..683973674f694 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -78,8 +78,15 @@ zend_throw_error(NULL, "No PostgreSQL connection opened yet"); \ RETURN_THROWS(); \ } + +/* This is a bit hacky as the macro usage is "link = FETCH_DEFAULT_LINK();" */ #define FETCH_DEFAULT_LINK() \ - (PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL) + (PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL); \ + php_error_docref(NULL, E_DEPRECATED, "Automatic fetching of PostgreSQL connection is deprecated") + +/* Used only when creating a connection */ +#define FETCH_DEFAULT_LINK_NO_WARNING() \ + (PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL) #define CHECK_PGSQL_LINK(link_handle) \ if (link_handle->conn == NULL) { \ @@ -850,7 +857,7 @@ PHP_FUNCTION(pg_close) link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); - if (link == FETCH_DEFAULT_LINK()) { + if (link == FETCH_DEFAULT_LINK_NO_WARNING()) { GC_DELREF(PGG(default_link)); PGG(default_link) = NULL; } diff --git a/ext/pgsql/tests/01createdb.phpt b/ext/pgsql/tests/01createdb.phpt index 512ddebc1e9d7..90eee3c314105 100644 --- a/ext/pgsql/tests/01createdb.phpt +++ b/ext/pgsql/tests/01createdb.phpt @@ -22,7 +22,7 @@ else { echo pg_last_error()."\n"; } -$v = pg_version(); +$v = pg_version($db); if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q))) { pg_query($db,$table_def_92); // Create table here diff --git a/ext/pgsql/tests/05large_object.phpt b/ext/pgsql/tests/05large_object.phpt index 26882734efd32..f4488ca5aa522 100644 --- a/ext/pgsql/tests/05large_object.phpt +++ b/ext/pgsql/tests/05large_object.phpt @@ -43,7 +43,7 @@ $handle = pg_lo_open ($db, $oid, "w"); $bytesWritten = pg_lo_read_all($handle); echo "\n"; var_dump($bytesWritten); -if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error(); +if (pg_last_error($db)) echo "pg_lo_read_all() error\n".pg_last_error(); pg_lo_close($handle); pg_exec ($db, "commit"); @@ -103,7 +103,7 @@ try { echo "OK"; ?> ---EXPECT-- +--EXPECTF-- create/write/close LO open/read/tell/seek/close LO string(5) "large" @@ -120,10 +120,16 @@ large object data int(17) unlink LO Test without connection + +Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Test with string oid value import/export LO + +Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed Invalid OID value passed + +Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed Invalid OID value passed OK diff --git a/ext/pgsql/tests/07optional.phpt b/ext/pgsql/tests/07optional.phpt index f91f43b6a9615..6c58727e4adbe 100644 --- a/ext/pgsql/tests/07optional.phpt +++ b/ext/pgsql/tests/07optional.phpt @@ -16,9 +16,9 @@ $enc = pg_client_encoding($db); pg_set_client_encoding($db, $enc); if (function_exists('pg_set_error_verbosity')) { - pg_set_error_verbosity(PGSQL_ERRORS_TERSE); - pg_set_error_verbosity(PGSQL_ERRORS_DEFAULT); - pg_set_error_verbosity(PGSQL_ERRORS_VERBOSE); + pg_set_error_verbosity($db, PGSQL_ERRORS_TERSE); + pg_set_error_verbosity($db, PGSQL_ERRORS_DEFAULT); + pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE); } echo "OK"; ?> diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt index 1f807281bc44e..64bbe5885fc98 100644 --- a/ext/pgsql/tests/08escape.phpt +++ b/ext/pgsql/tests/08escape.phpt @@ -44,8 +44,8 @@ $data = file_get_contents(FILE_NAME); $db = pg_connect($conn_str); // Insert binary to DB -$escaped_data = pg_escape_bytea($data); -pg_query("DELETE FROM ".$table_name." WHERE num = 10000;"); +$escaped_data = pg_escape_bytea($db, $data); +pg_query($db, "DELETE FROM ".$table_name." WHERE num = 10000;"); $sql = "INSERT INTO ".$table_name." (num, bin) VALUES (10000, CAST ('".$escaped_data."' AS BYTEA));"; pg_query($db, $sql); @@ -73,7 +73,7 @@ for ($i = 0; $i < 2; $i++) { // pg_escape_literal/pg_escape_identifier $before = "ABC\\ABC\'"; $expect = " E'ABC\\\\ABC\\\\'''"; -$after = pg_escape_literal($before); +$after = pg_escape_literal($db, $before); if ($expect === $after) { echo "pg_escape_literal() is Ok\n"; } @@ -86,7 +86,7 @@ else { $before = "ABC\\ABC\'"; $expect = "\"ABC\ABC\'\""; -$after = pg_escape_identifier($before); +$after = pg_escape_identifier($db, $before); if ($expect === $after) { echo "pg_escape_identifier() is Ok\n"; } @@ -98,8 +98,11 @@ else { } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d pg_escape_string() is Ok + +Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d pg_escape_bytea() is Ok pg_escape_bytea() actually works with database pg_escape_literal() is Ok diff --git a/ext/pgsql/tests/09notice.phpt b/ext/pgsql/tests/09notice.phpt index d75c8f589330a..c27f010f07cc2 100644 --- a/ext/pgsql/tests/09notice.phpt +++ b/ext/pgsql/tests/09notice.phpt @@ -7,7 +7,7 @@ pgsql include("skipif.inc"); -_skip_lc_messages(); +_skip_lc_messages($conn); ?> --FILE-- @@ -20,7 +20,7 @@ ini_set('pgsql.ignore_notice', FALSE); $db = pg_connect($conn_str); -_set_lc_messages(); +_set_lc_messages($db); $res = pg_query($db, 'SET client_min_messages TO NOTICE;'); var_dump($res); diff --git a/ext/pgsql/tests/13pg_select_9.phpt b/ext/pgsql/tests/13pg_select_9.phpt index 86d68ad68e98c..9246288e5c8c0 100644 --- a/ext/pgsql/tests/13pg_select_9.phpt +++ b/ext/pgsql/tests/13pg_select_9.phpt @@ -14,7 +14,7 @@ error_reporting(E_ALL); include 'config.inc'; $db = pg_connect($conn_str); -pg_query("SET bytea_output = 'hex'"); +pg_query($db, "SET bytea_output = 'hex'"); $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ'); $ids = array('num'=>'1234'); diff --git a/ext/pgsql/tests/18pg_escape_bytea_before.phpt b/ext/pgsql/tests/18pg_escape_bytea_before.phpt index 052a8bc4a392c..c55fdf3ba4d66 100644 --- a/ext/pgsql/tests/18pg_escape_bytea_before.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea_before.phpt @@ -28,5 +28,6 @@ else { echo "OK"; } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d OK diff --git a/ext/pgsql/tests/18pg_escape_bytea_esc.phpt b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt index 5942c98328bcd..57cdf9e2378d8 100644 --- a/ext/pgsql/tests/18pg_escape_bytea_esc.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt @@ -14,7 +14,7 @@ $db = pg_connect($conn_str); @pg_query($db, "SET bytea_output = 'escape'"); $image = file_get_contents(__DIR__ . '/php.gif'); -$esc_image = pg_escape_bytea($image); +$esc_image = pg_escape_bytea($db, $image); pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');'); $result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876'); diff --git a/ext/pgsql/tests/18pg_escape_bytea_hex.phpt b/ext/pgsql/tests/18pg_escape_bytea_hex.phpt index 0ccbe45b14d66..4d68030e6f035 100644 --- a/ext/pgsql/tests/18pg_escape_bytea_hex.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea_hex.phpt @@ -17,7 +17,7 @@ $db = pg_connect($conn_str); @pg_query($db, "SET bytea_output = 'hex'"); $image = file_get_contents(__DIR__ . '/php.gif'); -$esc_image = pg_escape_bytea($image); +$esc_image = pg_escape_bytea($db, $image); pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');'); $result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876'); diff --git a/ext/pgsql/tests/27large_object_oid.phpt b/ext/pgsql/tests/27large_object_oid.phpt index 4ac44a8920bf4..4581d18a88080 100644 --- a/ext/pgsql/tests/27large_object_oid.phpt +++ b/ext/pgsql/tests/27large_object_oid.phpt @@ -42,8 +42,16 @@ pg_exec ("commit"); echo "OK"; ?> ---EXPECT-- +--EXPECTF-- create LO from int create LO from string create LO using default connection + +Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d OK diff --git a/ext/pgsql/tests/28large_object_import_oid.phpt b/ext/pgsql/tests/28large_object_import_oid.phpt index 868588027118c..3af7529333989 100644 --- a/ext/pgsql/tests/28large_object_import_oid.phpt +++ b/ext/pgsql/tests/28large_object_import_oid.phpt @@ -84,14 +84,26 @@ try { echo "OK"; ?> ---EXPECT-- +--EXPECTF-- import LO from int import LO from string import LO using default connection + +Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed Invalid OID value passed + +Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed Invalid OID value passed + +Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d OID value must be of type string|int, bool given OID value must be of type string|int, array given OID value must be of type string|int, stdClass given diff --git a/ext/pgsql/tests/80_bug24499.phpt b/ext/pgsql/tests/80_bug24499.phpt index 26ba18666e13f..18ec3293c9cc3 100644 --- a/ext/pgsql/tests/80_bug24499.phpt +++ b/ext/pgsql/tests/80_bug24499.phpt @@ -16,12 +16,12 @@ if (!$dbh) { die ("Could not connect to the server"); } -@pg_query("DROP SEQUENCE id_id_seq"); -@pg_query("DROP TABLE id"); -pg_query("CREATE TABLE id (id SERIAL, t INT)"); +@pg_query($dbh, "DROP SEQUENCE id_id_seq"); +@pg_query($dbh, "DROP TABLE id"); +pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)"); for ($i=0; $i<4; $i++) { - pg_query("INSERT INTO id (t) VALUES ($i)"); + pg_query($dbh, "INSERT INTO id (t) VALUES ($i)"); } class Id diff --git a/ext/pgsql/tests/80_bug27597.phpt b/ext/pgsql/tests/80_bug27597.phpt index 2d92722ef2aa5..b296c4e85ad81 100644 --- a/ext/pgsql/tests/80_bug27597.phpt +++ b/ext/pgsql/tests/80_bug27597.phpt @@ -16,11 +16,11 @@ if (!$dbh) { die ("Could not connect to the server"); } -@pg_query("DROP TABLE id"); -pg_query("CREATE TABLE id (id INT)"); +@pg_query($dbh, "DROP TABLE id"); +pg_query($dbh, "CREATE TABLE id (id INT)"); for ($i=0; $i<4; $i++) { - pg_query("INSERT INTO id (id) VALUES ($i)"); + pg_query($dbh, "INSERT INTO id (id) VALUES ($i)"); } function xi_fetch_array($res, $type = PGSQL_ASSOC) { @@ -28,7 +28,7 @@ function xi_fetch_array($res, $type = PGSQL_ASSOC) { return $a ; } -$res = pg_query("SELECT * FROM id"); +$res = pg_query($dbh, "SELECT * FROM id"); $i = 0; // endless-loop protection while($row = xi_fetch_array($res)) { print_r($row); diff --git a/ext/pgsql/tests/80_bug32223.phpt b/ext/pgsql/tests/80_bug32223.phpt index a658031b968fc..2a1ef631c0df6 100644 --- a/ext/pgsql/tests/80_bug32223.phpt +++ b/ext/pgsql/tests/80_bug32223.phpt @@ -6,7 +6,7 @@ pgsql 'now()'); pg_insert($dbh, 'php_test', $values); diff --git a/ext/pgsql/tests/80_bug42783.phpt b/ext/pgsql/tests/80_bug42783.phpt index 1e9fc7dd7df6b..4a15f62e9e653 100644 --- a/ext/pgsql/tests/80_bug42783.phpt +++ b/ext/pgsql/tests/80_bug42783.phpt @@ -16,11 +16,11 @@ if (!$dbh) { die ("Could not connect to the server"); } -pg_query("CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())"); +pg_query($dbh, "CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())"); pg_insert($dbh, 'php_test', array()); -var_dump(pg_fetch_assoc(pg_query("SELECT * FROM php_test"))); +var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM php_test"))); pg_query($dbh, "DROP TABLE php_test"); pg_close($dbh); diff --git a/ext/pgsql/tests/98old_api.phpt b/ext/pgsql/tests/98old_api.phpt index ad4b4334c834f..db75a943dba08 100644 --- a/ext/pgsql/tests/98old_api.phpt +++ b/ext/pgsql/tests/98old_api.phpt @@ -10,7 +10,7 @@ pgsql include('config.inc'); $db = pg_connect($conn_str); -$result = pg_exec("SELECT * FROM ".$table_name); +$result = pg_exec($db, "SELECT * FROM ".$table_name); pg_numrows($result); pg_numfields($result); pg_fieldname($result, 0); @@ -20,11 +20,11 @@ pg_fieldprtlen($result, 0); pg_fieldisnull($result, 0); pg_result($result,0,0); -$result = pg_exec("INSERT INTO ".$table_name." VALUES (7777, 'KKK')"); +$result = pg_exec($db, "INSERT INTO ".$table_name." VALUES (7777, 'KKK')"); $oid = pg_getlastoid($result); pg_freeresult($result); -pg_errormessage(); -$result = pg_exec("UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';"); +pg_errormessage($db); +$result = pg_exec($db, "UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';"); pg_cmdtuples($result); diff --git a/ext/pgsql/tests/bug37100_9.phpt b/ext/pgsql/tests/bug37100_9.phpt index 78230df13aa30..307e9e60f729e 100644 --- a/ext/pgsql/tests/bug37100_9.phpt +++ b/ext/pgsql/tests/bug37100_9.phpt @@ -14,20 +14,20 @@ include 'config.inc'; $db = pg_connect($conn_str); -@pg_query('DROP TABLE test_bug'); +@pg_query($db, 'DROP TABLE test_bug'); -pg_query('CREATE TABLE test_bug (binfield byteA) ;'); -pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))"); +pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;'); +pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))"); -$data = pg_query("SELECT binfield FROM test_bug"); +$data = pg_query($db, "SELECT binfield FROM test_bug"); $res = pg_fetch_result($data,0); var_dump($res); var_dump(bin2hex(pg_unescape_bytea($res))); $sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;"; -$data = pg_query($sql); +$data = pg_query($db, $sql); $res = pg_fetch_result($data,0); var_dump(strlen($res)); @@ -36,7 +36,7 @@ var_dump(bin2hex($res)); pg_close($db); $db = pg_connect($conn_str); -pg_query('DROP TABLE test_bug'); +pg_query($db, 'DROP TABLE test_bug'); pg_close($db); diff --git a/ext/pgsql/tests/bug46408.phpt b/ext/pgsql/tests/bug46408.phpt index 44382233e4d5c..2a9ffeca4d697 100644 --- a/ext/pgsql/tests/bug46408.phpt +++ b/ext/pgsql/tests/bug46408.phpt @@ -17,7 +17,7 @@ require_once('config.inc'); $dbh = pg_connect($conn_str); setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8"); echo 3.5 , "\n"; -pg_query_params("SELECT $1::numeric", array(3.5)); +pg_query_params($dbh, "SELECT $1::numeric", array(3.5)); pg_close($dbh); echo "Done".PHP_EOL; diff --git a/ext/pgsql/tests/bug47199.phpt b/ext/pgsql/tests/bug47199.phpt index f1f8ccf028410..0c2390371e88f 100644 --- a/ext/pgsql/tests/bug47199.phpt +++ b/ext/pgsql/tests/bug47199.phpt @@ -13,13 +13,13 @@ require_once('config.inc'); $dbh = pg_connect($conn_str); $tbl_name = 'test_47199'; -@pg_query("DROP TABLE $tbl_name"); -pg_query("CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)"); +@pg_query($dbh, "DROP TABLE $tbl_name"); +pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)"); pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1)); pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2)); -var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); +var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name))); $query = pg_delete($dbh, $tbl_name, array('null_field' => NULL,'not_null_field' => 2), PGSQL_DML_STRING|PGSQL_DML_EXEC); @@ -29,9 +29,9 @@ $query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' echo $query, "\n"; -var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); +var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name))); -@pg_query("DROP TABLE $tbl_name"); +@pg_query($dbh, "DROP TABLE $tbl_name"); pg_close($dbh); echo PHP_EOL."Done".PHP_EOL; diff --git a/ext/pgsql/tests/bug60244.phpt b/ext/pgsql/tests/bug60244.phpt index 1cf68f2d3dc5e..50a9d7a831dd9 100644 --- a/ext/pgsql/tests/bug60244.phpt +++ b/ext/pgsql/tests/bug60244.phpt @@ -12,7 +12,7 @@ include("skipif.inc"); include 'config.inc'; $db = pg_connect($conn_str); -$result = pg_query("select 'a' union select 'b'"); +$result = pg_query($db, "select 'a' union select 'b'"); try { var_dump(pg_fetch_array($result, -1)); diff --git a/ext/pgsql/tests/bug64609.phpt b/ext/pgsql/tests/bug64609.phpt index b0192c4ae84c6..ebf878dbeed9e 100644 --- a/ext/pgsql/tests/bug64609.phpt +++ b/ext/pgsql/tests/bug64609.phpt @@ -14,14 +14,14 @@ error_reporting(E_ALL); include 'config.inc'; $db = pg_connect($conn_str); -pg_query("BEGIN"); -pg_query("CREATE TYPE t_enum AS ENUM ('ok', 'ko')"); -pg_query("CREATE TABLE test_enum (a t_enum)"); +pg_query($db, "BEGIN"); +pg_query($db, "CREATE TYPE t_enum AS ENUM ('ok', 'ko')"); +pg_query($db, "CREATE TABLE test_enum (a t_enum)"); $fields = array('a' => 'ok'); $converted = pg_convert($db, 'test_enum', $fields); -pg_query("ROLLBACK"); +pg_query($db, "ROLLBACK"); var_dump($converted); ?> diff --git a/ext/pgsql/tests/bug65119.phpt b/ext/pgsql/tests/bug65119.phpt index ce7e3e50114d7..f2e46ca137ddd 100644 --- a/ext/pgsql/tests/bug65119.phpt +++ b/ext/pgsql/tests/bug65119.phpt @@ -12,10 +12,10 @@ include 'config.inc'; function test(Array $values, $conn_str) { $connection = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW); - pg_query("begin"); - pg_query("CREATE TABLE bug65119 (i INTEGER)"); + pg_query($connection, "begin"); + pg_query($connection, "CREATE TABLE bug65119 (i INTEGER)"); pg_copy_from($connection, "bug65119", $values, "\t", "NULL"); - pg_query("rollback"); + pg_query($connection, "rollback"); } $values = Array(1,2,3); diff --git a/ext/pgsql/tests/bug68638.phpt b/ext/pgsql/tests/bug68638.phpt index e3a34a036eab3..d95fa1e44125d 100644 --- a/ext/pgsql/tests/bug68638.phpt +++ b/ext/pgsql/tests/bug68638.phpt @@ -13,7 +13,7 @@ $conn = pg_connect($conn_str); $table='test_68638'; -pg_query("CREATE TABLE $table (id INT, value FLOAT)"); +pg_query($conn, "CREATE TABLE $table (id INT, value FLOAT)"); pg_insert($conn,$table, array('id' => 1, 'value' => 1.2)); pg_insert($conn,$table, array('id' => 2, 'value' => 10)); @@ -25,12 +25,12 @@ pg_update($conn,$table, array('value' => 'inf'), array('id' => 1)); pg_update($conn,$table, array('value' => '-inf'), array('id' => 2)); pg_update($conn,$table, array('value' => '+inf'), array('id' => 3)); -$rs = pg_query("SELECT * FROM $table"); +$rs = pg_query($conn, "SELECT * FROM $table"); while ($row = pg_fetch_assoc($rs)) { var_dump($row); } -pg_query("DROP TABLE $table"); +pg_query($conn, "DROP TABLE $table"); ?> --EXPECT-- diff --git a/ext/pgsql/tests/bug71998.phpt b/ext/pgsql/tests/bug71998.phpt index 9193c7e490dc7..854c4e4227436 100644 --- a/ext/pgsql/tests/bug71998.phpt +++ b/ext/pgsql/tests/bug71998.phpt @@ -13,7 +13,7 @@ include('config.inc'); $db = pg_connect($conn_str); -pg_query("CREATE TABLE tmp_statistics (id integer NOT NULL, remote_addr inet);"); +pg_query($db, "CREATE TABLE tmp_statistics (id integer NOT NULL, remote_addr inet);"); $ips = array( /* IPv4*/ diff --git a/ext/pgsql/tests/bug72028.phpt b/ext/pgsql/tests/bug72028.phpt index 21258cf700186..9829cb1445098 100644 --- a/ext/pgsql/tests/bug72028.phpt +++ b/ext/pgsql/tests/bug72028.phpt @@ -14,7 +14,7 @@ $conn = pg_connect($conn_str); $table = "bug72028_" . md5(uniqid(time())); -pg_query("CREATE TABLE $table (value TEXT, details TEXT);"); +pg_query($conn, "CREATE TABLE $table (value TEXT, details TEXT);"); $sql = "INSERT INTO $table (value, details) VALUES ($1, $2)"; @@ -29,12 +29,12 @@ unset($p); $result = pg_query_params($conn, $sql, $params2); -$r = pg_query("SELECT * FROM $table"); +$r = pg_query($conn, "SELECT * FROM $table"); while (false !== ($i = pg_fetch_assoc($r))) { var_dump($i); } -pg_query("DROP TABLE $table"); +pg_query($conn, "DROP TABLE $table"); ?> --EXPECT-- diff --git a/ext/pgsql/tests/bug72197.phpt b/ext/pgsql/tests/bug72197.phpt index 898a94fef3a6b..04825c83045a3 100644 --- a/ext/pgsql/tests/bug72197.phpt +++ b/ext/pgsql/tests/bug72197.phpt @@ -35,4 +35,6 @@ pg_close($conn); --EXPECTF-- pg_lo_create(): Argument #1 ($connection) must be of type PgSql\Connection when the connection is provided%w int(%d) + +Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d int(%d) diff --git a/ext/pgsql/tests/bug75419.phpt b/ext/pgsql/tests/bug75419.phpt index 8aa4e83d5b285..6c1b2bd62278c 100644 --- a/ext/pgsql/tests/bug75419.phpt +++ b/ext/pgsql/tests/bug75419.phpt @@ -13,5 +13,6 @@ $db2 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW); pg_close($db1); var_dump(pg_ping()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: pg_ping(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d bool(true) diff --git a/ext/pgsql/tests/close_default_link.phpt b/ext/pgsql/tests/close_default_link.phpt index 9aaf3a42e9407..db9851cebebc5 100644 --- a/ext/pgsql/tests/close_default_link.phpt +++ b/ext/pgsql/tests/close_default_link.phpt @@ -13,5 +13,6 @@ $db1 = pg_connect($conn_str); unset($db1); var_dump(pg_close()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d bool(true) diff --git a/ext/pgsql/tests/connect_after_close.phpt b/ext/pgsql/tests/connect_after_close.phpt index 4e3f7b12cd712..1f450a88e0d13 100644 --- a/ext/pgsql/tests/connect_after_close.phpt +++ b/ext/pgsql/tests/connect_after_close.phpt @@ -17,6 +17,9 @@ $db2 = pg_connect($conn_str); unset($db2); var_dump(pg_close()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d bool(true) + +Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d bool(true) diff --git a/ext/pgsql/tests/deprecated_implicit_default_link.phpt b/ext/pgsql/tests/deprecated_implicit_default_link.phpt new file mode 100644 index 0000000000000..7c508e0da9569 --- /dev/null +++ b/ext/pgsql/tests/deprecated_implicit_default_link.phpt @@ -0,0 +1,144 @@ +--TEST-- +PostgreSQL fetching default link automatically is deprecated +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- +getMessage(), 'type array')) { + $args[$argNum] = []; + goto retry; + } + var_dump($e->getMessage()); + } catch (\Error $e) { + echo $e->getMessage(); + } +} + +echo "END"; +?> +--EXPECTF-- +Deprecated: pg_set_error_verbosity(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_query_params(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_execute(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_open(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_export(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_dbname(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_last_error(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_options(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_port(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_tty(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_host(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_version(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_parameter_status(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_ping(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_query(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_prepare(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_untrace(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_set_client_encoding(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_client_encoding(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_end_copy(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_put_line(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_escape_literal(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_escape_identifier(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d + +Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d +END diff --git a/ext/pgsql/tests/lcmess.inc b/ext/pgsql/tests/lcmess.inc index 8c2171547709f..7c6e0b80ed7ba 100644 --- a/ext/pgsql/tests/lcmess.inc +++ b/ext/pgsql/tests/lcmess.inc @@ -1,16 +1,16 @@ ---EXPECT-- +--EXPECTF-- +Deprecated: pg_dbname(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d No PostgreSQL connection opened yet diff --git a/ext/pgsql/tests/pg_delete_001.phpt b/ext/pgsql/tests/pg_delete_001.phpt index 7e1937afbebce..abf01a6b53f6d 100644 --- a/ext/pgsql/tests/pg_delete_001.phpt +++ b/ext/pgsql/tests/pg_delete_001.phpt @@ -11,10 +11,10 @@ include('config.inc'); $conn = pg_connect($conn_str); -pg_query('CREATE SCHEMA phptests'); +pg_query($conn, 'CREATE SCHEMA phptests'); -pg_query('CREATE TABLE foo (id INT, id2 INT)'); -pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE TABLE foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)'); pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2)); @@ -34,16 +34,16 @@ pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1)); pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING)); -var_dump(pg_fetch_all(pg_query('SELECT * FROM foo'))); -var_dump(pg_fetch_all(pg_query('SELECT * FROM phptests.foo'))); +var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM foo'))); +var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM phptests.foo'))); /* Inexistent */ pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2)); var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); -pg_query('DROP TABLE foo'); -pg_query('DROP TABLE phptests.foo'); -pg_query('DROP SCHEMA phptests'); +pg_query($conn, 'DROP TABLE foo'); +pg_query($conn, 'DROP TABLE phptests.foo'); +pg_query($conn, 'DROP SCHEMA phptests'); ?> --EXPECTF-- diff --git a/ext/pgsql/tests/pg_insert_001.phpt b/ext/pgsql/tests/pg_insert_001.phpt index 90c328ef27011..b3e934692cf24 100644 --- a/ext/pgsql/tests/pg_insert_001.phpt +++ b/ext/pgsql/tests/pg_insert_001.phpt @@ -11,8 +11,8 @@ include('config.inc'); $conn = pg_connect($conn_str); -pg_query('CREATE SCHEMA phptests'); -pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE SCHEMA phptests'); +pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)'); pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); @@ -23,8 +23,8 @@ var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DM var_dump(pg_select($conn, 'phptests.foo', array('id' => 1))); -pg_query('DROP TABLE phptests.foo'); -pg_query('DROP SCHEMA phptests'); +pg_query($conn, 'DROP TABLE phptests.foo'); +pg_query($conn, 'DROP SCHEMA phptests'); ?> --EXPECTF-- diff --git a/ext/pgsql/tests/pg_meta_data_001.phpt b/ext/pgsql/tests/pg_meta_data_001.phpt index 0a147f9da4fda..72f2f4fa5ad48 100644 --- a/ext/pgsql/tests/pg_meta_data_001.phpt +++ b/ext/pgsql/tests/pg_meta_data_001.phpt @@ -11,11 +11,11 @@ include('config.inc'); $conn = pg_connect($conn_str); -pg_query('CREATE SCHEMA phptests'); +pg_query($conn, 'CREATE SCHEMA phptests'); -pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)'); -pg_query('CREATE TABLE foo (id INT, id3 INT)'); +pg_query($conn, 'CREATE TABLE foo (id INT, id3 INT)'); var_dump(pg_meta_data($conn, 'foo')); @@ -23,9 +23,9 @@ var_dump(pg_meta_data($conn, 'phptests.foo')); var_dump(pg_meta_data($conn, 'phptests.foo', TRUE)); -pg_query('DROP TABLE foo'); -pg_query('DROP TABLE phptests.foo'); -pg_query('DROP SCHEMA phptests'); +pg_query($conn, 'DROP TABLE foo'); +pg_query($conn, 'DROP TABLE phptests.foo'); +pg_query($conn, 'DROP SCHEMA phptests'); ?> --EXPECT-- diff --git a/ext/pgsql/tests/pg_select_001.phpt b/ext/pgsql/tests/pg_select_001.phpt index c2ec12e093093..838182740dcd9 100644 --- a/ext/pgsql/tests/pg_select_001.phpt +++ b/ext/pgsql/tests/pg_select_001.phpt @@ -11,17 +11,17 @@ include('config.inc'); $conn = pg_connect($conn_str); -pg_query('CREATE SCHEMA phptests'); +pg_query($conn, 'CREATE SCHEMA phptests'); -pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); -pg_query('INSERT INTO phptests.foo VALUES (1,2)'); -pg_query('INSERT INTO phptests.foo VALUES (2,3)'); +pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query($conn, 'INSERT INTO phptests.foo VALUES (1,2)'); +pg_query($conn, 'INSERT INTO phptests.foo VALUES (2,3)'); -pg_query('CREATE TABLE phptests.bar (id4 INT, id3 INT)'); -pg_query('INSERT INTO phptests.bar VALUES (4,5)'); -pg_query('INSERT INTO phptests.bar VALUES (6,7)'); +pg_query($conn, 'CREATE TABLE phptests.bar (id4 INT, id3 INT)'); +pg_query($conn, 'INSERT INTO phptests.bar VALUES (4,5)'); +pg_query($conn, 'INSERT INTO phptests.bar VALUES (6,7)'); -/* Inexistent table */ +/* Nonexistent table */ var_dump(pg_select($conn, 'foo', array('id' => 1))); /* Existent column */ @@ -36,9 +36,9 @@ var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4))); /* Use a different result type */ var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4), 0, PGSQL_NUM)); -pg_query('DROP TABLE phptests.foo'); -pg_query('DROP TABLE phptests.bar'); -pg_query('DROP SCHEMA phptests'); +pg_query($conn, 'DROP TABLE phptests.foo'); +pg_query($conn, 'DROP TABLE phptests.bar'); +pg_query($conn, 'DROP SCHEMA phptests'); ?> --EXPECTF-- diff --git a/ext/pgsql/tests/pg_update_001.phpt b/ext/pgsql/tests/pg_update_001.phpt index a74a1944ac008..eb3958a23135a 100644 --- a/ext/pgsql/tests/pg_update_001.phpt +++ b/ext/pgsql/tests/pg_update_001.phpt @@ -11,10 +11,10 @@ include('config.inc'); $conn = pg_connect($conn_str); -pg_query('CREATE SCHEMA phptests'); +pg_query($conn, 'CREATE SCHEMA phptests'); -pg_query('CREATE TABLE foo (id INT, id2 INT)'); -pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE TABLE foo (id INT, id2 INT)'); +pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)'); pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); @@ -26,14 +26,14 @@ var_dump(pg_update($conn, 'foo', array('id' => 10), array('id' => 1), PGSQL_DML_ pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2)); var_dump(pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2), PGSQL_DML_STRING)); -$rs = pg_query('SELECT * FROM foo UNION SELECT * FROM phptests.foo ORDER BY id'); +$rs = pg_query($conn, 'SELECT * FROM foo UNION SELECT * FROM phptests.foo ORDER BY id'); while ($row = pg_fetch_assoc($rs)) { var_dump($row); } -pg_query('DROP TABLE foo'); -pg_query('DROP TABLE phptests.foo'); -pg_query('DROP SCHEMA phptests'); +pg_query($conn, 'DROP TABLE foo'); +pg_query($conn, 'DROP TABLE phptests.foo'); +pg_query($conn, 'DROP SCHEMA phptests'); ?> --EXPECT-- diff --git a/ext/pgsql/tests/skipif.inc b/ext/pgsql/tests/skipif.inc index ca67b610ebc37..06c3ff657115b 100644 --- a/ext/pgsql/tests/skipif.inc +++ b/ext/pgsql/tests/skipif.inc @@ -1,3 +1,4 @@ + = 9.0\n"); }