pg_copy_to

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_copy_to Copie une table dans un tableau

Description

pg_copy_to(
    resource $connection,
    string $table_name,
    string $delimiter = ?,
    string $null_as = ?
): array

pg_copy_to() copie la table table_name dans un tableau. Cette fonction utilise la commande interne SQL COPY TO pour insérer les tableaux.

Liste de paramètres

connection

Ressource de connexion de base de données PostgreSQL.

table_name

Nom de la table à partir de laquelle les données dans rows seront copiées.

delimiter

Le marqueur qui sépare les valeurs pour chaque champ dans chaque élément de rows. La valeur par défaut est TAB.

null_as

Comment les valeurs NULL de SQL sont représentées dans rows. La valeur par défaut est \N ("\\N").

Valeurs de retour

Un tableau avec un élément pour chaque ligne de données COPY. La fonction retourne false en cas d'échec.

Exemples

Exemple #1 Exemple avec pg_copy_to()

<?php
   $db 
pg_connect("dbname=publisher") or die("Connexion impossible");
   
   
$rows pg_copy_to($db$table_name);
   
   
pg_query($db"DELETE FROM $table_name");
   
   
pg_copy_from($db$table_name$rows);
?>

Voir aussi

  • pg_copy_from() - Insère des lignes dans une table à partir d'un tableau

add a note add a note

User Contributed Notes 3 notes

up
1
John M
3 years ago
Worth noting here that just like the COPY TO statement in PostgreSQL, '$table_name' can include a list of columns or be a select query as well.
e.g.:
$rows = pg_copy_to($db,'schema."TableName" (column1, column2, ...)';
$rows = pg_copy_to($db,'(SELECT ...)');
up
0
setantae at submonkey dot net
21 years ago
"It issues COPY TO SQL command internally to insert records"

I suspect this statement is incorrect, or that s/insert/retrieve/ is appropriate.
up
-3
etiger13 at gmail dot com
14 years ago
You cannot specify the schema name in this command. You can change the search path for just one query by using the following code:

<?php
pg_query
($conn, "SET search_path TO myschema;");
   
$copy_to = pg_copy_to($conn, 'tablename');
   
pg_query("RESET search_path;");
?>
To Top