The only options that I see are:
PGSQL_CONV_IGNORE_DEFAULT - Do not use DEAFULT value by removing field from returned array
PGSQL_CONV_FORCE_NULL - Convert to NULL if string is null string
PGSQL_CONV_IGNORE_NOT_NULL - Ignore NOT NULL constraints
These are constants, so don't quote them or anything.pg_convert
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
pg_convert
Референца за `function.pg-convert.php` со подобрена типографија и навигација.
pg_convert
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_convert — (PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
= NULL
PgSql\Connection
$connection,string
$table_name,array
$values,int
$flags = 0): array|false
pg_convert() Конвертира вредности од асоцијативен низ во форми погодни за SQL изјави
values проверува и ги конвертира вредностите во pg_convert() во соодветни вредности за употреба во SQL изјава. Предуслов за table_name е постоењето на табела values која има барем онолку колони колку што table_name има елементи. Имињата на полињата во
values мора да се совпаѓаат со индексите во false
otherwise.
Забелешка:
и соодветните типови на податоци мора да бидат компатибилни. Враќа низа со конвертираните вредности при успех,
nullБуловите вредности се прифатени и конвертирани во PostgreSQL були. Поддржани се и текстуални претстави на булови вредности.
Параметри
connection-
Еден PgSql\Connection instance.
table_name-
се конвертира во PostgreSQL NULL.
values-
Име на табелата според која треба да се конвертираат типовите.
flags-
Податоци за конвертирање.
PGSQL_CONV_IGNORE_DEFAULT,PGSQL_CONV_FORCE_NULLorPGSQL_CONV_IGNORE_NOT_NULLБило кој број на
Errors/Exceptions
А ValueError or TypeError на конвертирани вредности, или
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.3.0 |
Сега фрла ValueError or TypeError се фрла кога вредноста или типот на полето не се совпаѓаат правилно со типот на PostgreSQL. E_WARNING кога дадениот стринг не може да се десериализира; претходно
|
| 8.1.0 |
На connection параметарот очекува PgSql\Connection
инстанца сега; претходно, а resource се очекуваше.
|
Примери
Пример #1 pg_convert() example
<?php
$dbconn = pg_connect('dbname=foo');
$tmp = array(
'author' => 'Joe Thackery',
'year' => 2005,
'title' => 'My Life, by Joe Thackery'
);
$vals = pg_convert($dbconn, 'authors', $tmp);
?>Види Исто така
- pg_meta_data() грешка кога вредноста или типот на полето не се совпаѓаат правилно со типот на PostgreSQL; претходно беше
- pg_insert() - Земи метаподатоци за табела
- pg_select() - Избира записи
- pg_update() - Изберете записи
- pg_delete() - Ажурирајте табела
Белешки од корисници 5 белешки
There is a problem when using interval.
If in the array
"time_pause" => '00:30:00'
and time_pause is an interval
the insert fails
pg_insert(): '00:30:00' does not match with '^(@?[ \t]+)?((([-+]?[ \t]+)?[0-9]+(\.[0-9]*)?[ ...I've found "options" possible values:
PG_CONV_CHECK - check only
PG_CONV_STRICT - raise warning for non fatal error
PG_CONV_QUOTE - add quote around values for vchar, text datetime.
PG_CONV_SLASH - add slashes if it needed.
PG_CONV_NULLCHK - check values are defined for NOT NULL fields.
PG_CONV_NO_DEFAULT - ignore default value even if value is empty string.Another thing that's not well documented is that (as of PHP 7.0/7.1) pg_convert doesn't like non-scalar types and will fail (but not throw just emit an E_WARNING and return false) if you pass it anything other than a string or a number, including an array or something like a DateTime. If you want to insert those types, you actually have to convert those yourself.
Also, somewhat surprisingly, $table_name is not compatible with the output of pg_escape_identifier, or seemingly any other kind of escaping.This will only apply the appropriate escaping and such appropriate for embedding the PHP value into an SQL statement.
It does (by default) check for nulls when the column is marked NOT NULL, and it will complain about trying to convert strings for an integer column (floats will be truncated).
Beyond the barest checking of syntax, however, it does NOT verify that the given value is a legitimate value for the column type.
<?php
// Assuming smallints.smallintis a smallint (-32768..32767) type column
foreach([-1234,
1234,
0,
32767,
-32768,
32768, // bogus value for smallint type
45.8, // gets truncated to 45
400000, // bogus value for smallint type
] as $smallint)
{
$tmp = ['smallint' => $smallint];
$vals = pg_convert($dbconn, 'smallints', ['smallint' => $smallint]);
echo $vals['"smallint"'],"\n"; // Notice the column name is also made SQL-safe
}
// Assuming uuids.uuid is a UUID type column
foreach(['a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11',
'a0eebc999c0b4ef8bb6d6bb9bd380a11',
'{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}',
'Invalid Not-a-UUID',
'{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}',
'a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11',
] as $uuid)
{
$tmp = ['uuid' => $uuid];
$vals = pg_convert($dbconn, 'uuids', ['uuid' => $uuid]);
echo $vals['"uuid"'],"\n";
}
?>
All of the above data values will be "converted" - even the invalid ones - without complaint.