mirror of
https://github.com/php/doc-it.git
synced 2026-03-27 09:02:09 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@81718 c90b9560-bf6c-de11-be94-00142212c4b1
295 lines
11 KiB
XML
295 lines
11 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- EN-Revision: 1.6 Maintainer: cucinato Status: working -->
|
|
<!-- CREDITS: fabio --><!-- CREDITS: cortesi --><!-- CREDITS: denny -->
|
|
<reference id="ref.pgsql">
|
|
<title>Funzioni PostgreSQL</title>
|
|
<titleabbrev>PostgreSQL</titleabbrev>
|
|
|
|
<partintro>
|
|
<para>
|
|
Postgres, sviluppato originariamente nel Dipartimento di Informatica dell'Unniversità di
|
|
Berkeley, ha anticipato molti dei concetti su oggetti e relazioni che ora
|
|
stanno diventando disponibili in alcuni database commerciali. Postgres fornisce
|
|
supporto per il linguaggio SQL/92/SQL99, integrità transazionale ed estensibilità
|
|
dei tipi. PostgreSQL è un discendente open source dell'originario
|
|
codice di Berkeley.
|
|
</para>
|
|
<para>
|
|
Il database PostgreSQL è un prodotto Open Source ed è disponibile
|
|
gratuitamente. Per utilizzare il supporto a PostgreSQL, occorre PosgreSQL 6.5 o
|
|
versioni più recenti. PostgreSQL 7.0 o successivi permettono di abilitare tutte le possibilità
|
|
di questo modulo. PostgreSQL ammette molte codifiche di carattere, tra cui
|
|
la codifica multibyte. La versione corrente e maggiori
|
|
informazioni su PostgreSQL sono disponibili su <ulink
|
|
url="&url.pgsql;">&url.pgsql;</ulink>.
|
|
</para>
|
|
<para>
|
|
Per abilitare il supporto PostgreSQL,
|
|
<option role="configure">--with-pgsql[=DIR]</option> è richiesto quando si compila
|
|
il PHP. Se è disponibile il modulo di libreria dinamico, questo può essere
|
|
caricato usando la direttiva <link linkend="ini.extension">extension</link>
|
|
in &php.ini; o la funzione <function>dl</function>.
|
|
Le direttive ini previste sono descritte in
|
|
<filename>php.ini-dist</filename> che è disribuito con il pacchetto dei sorgenti.
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
L'utilizzo del modulo PostgreSQL con PHP 4.0.6 non è raccomandato a causa
|
|
di un bug nella gestione dei messaggi. Si usi PHP 4.1.0 o successivi.
|
|
</para>
|
|
</warning>
|
|
<warning>
|
|
<para>
|
|
I nomi delle funzioni relative a PostgreSQL verranno cambiate a partire dalla versione 4.2.0 per
|
|
conformarsi agli standard di sviluppo attuali. La maggior parte dei nuovi nomi avrà
|
|
underscore aggiuntivi, per esempio pg_lo_open(). Alcune funzioni verranno rinominate
|
|
per dare consistenza. Per esempio pg_exec() diventerà
|
|
pg_query(). I vecchi nomi potranno essere usati nella versione 4.2.0 e in alcune versioni
|
|
successive alla 4.2.0, ma potranno essere cancellate in futuro.
|
|
</para>
|
|
<table>
|
|
<title>Nomi di funzione cambiati</title>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>Vecchio nome</entry>
|
|
<entry>Nuovo nome</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><function>pg_exec</function></entry>
|
|
<entry><function>pg_query</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_getlastoid</function></entry>
|
|
<entry><function>pg_last_oid</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_cmdtuples</function></entry>
|
|
<entry><function>pg_affected_rows</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_numrows</function></entry>
|
|
<entry><function>pg_num_rows</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_numfields</function></entry>
|
|
<entry><function>pg_num_fields</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_fieldname</function></entry>
|
|
<entry><function>pg_field_name</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_fieldsize</function></entry>
|
|
<entry><function>pg_field_size</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_fieldnum</function></entry>
|
|
<entry><function>pg_field_num</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_fieldprtlen</function></entry>
|
|
<entry><function>pg_field_prtlen</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_fieldisnull</function></entry>
|
|
<entry><function>pg_field_is_null</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_freeresult</function></entry>
|
|
<entry><function>pg_free_result</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_result</function></entry>
|
|
<entry><function>pg_fetch_result</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loreadall</function></entry>
|
|
<entry><function>pg_lo_read_all</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_locreate</function></entry>
|
|
<entry><function>pg_lo_create</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_lounlink</function></entry>
|
|
<entry><function>pg_lo_unlink</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loopen</function></entry>
|
|
<entry><function>pg_lo_open</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loclose</function></entry>
|
|
<entry><function>pg_lo_close</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loread</function></entry>
|
|
<entry><function>pg_lo_read</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_lowrite</function></entry>
|
|
<entry><function>pg_lo_write</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loimport</function></entry>
|
|
<entry><function>pg_lo_import</function></entry>
|
|
</row>
|
|
<row>
|
|
<entry><function>pg_loexport</function></entry>
|
|
<entry><function>pg_lo_export</function></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
<para>
|
|
La vecchia sintassi di <function>pg_connect</function>/<function>pg_pconnect</function>
|
|
sarà deprecata per supportare, in futuro, connessioni asincrone.
|
|
Si usi una stringa di connessione con <function>pg_connect</function> e
|
|
<function>pg_pconnect</function>.
|
|
</para>
|
|
</warning>
|
|
<para>
|
|
Non tutte le funzioni sono supportate su tutte le architetture. Dipende dalla versione
|
|
di libpq (L'interfaccia Client C per PostgreSQL) e da come libpq è
|
|
compilato. Se c'è una funzione mancante, libpq non supporta
|
|
la feature richiesta per quella funzione.
|
|
</para>
|
|
<para>
|
|
È importante usare versioni di libpq più recenti rispetto al Server
|
|
PostgreSQL al quale ci si vuole collegare. Se si usa una versione di libpq più vecchia rispetto
|
|
al Server PostgreSQL al quale ci si vuole collegare, si andrà probabilmente incontro a problemi.
|
|
</para>
|
|
<para>
|
|
Fin dalla versione 6.3 (03/02/1998) PostgreSQL usa gli unix domain socket
|
|
di default. La porta TCP, di default, NON verrà aperta. La tabella
|
|
sottostante descrive queste nuove possibilità di connessione. Questo
|
|
socket può essere trovato in <filename>/tmp/.s.PGSQL.5432</filename>.
|
|
Questa opzione può venire abilitata con la flag '-i' a
|
|
<command>postmaster</command> e il suo significato è: "ascolta i
|
|
socket TCP/IP così come gli Unix domain socket".
|
|
<table>
|
|
<title>Postmaster e PHP</title>
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Postmaster</entry>
|
|
<entry>PHP</entry>
|
|
<entry>Status</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>postmaster &</entry>
|
|
<entry>pg_connect("dbname=NomeMioDatabase");</entry>
|
|
<entry>OK</entry>
|
|
</row>
|
|
<row>
|
|
<entry>postmaster -i &</entry>
|
|
<entry>pg_connect("dbname=NomeMioDatabase");</entry>
|
|
<entry>OK</entry>
|
|
</row>
|
|
<row>
|
|
<entry>postmaster &</entry>
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
<entry>
|
|
Unable to connect to PostgreSQL server: connectDB() failed:
|
|
Is the postmaster running and accepting TCP/IP (with -i)
|
|
connection at 'localhost' on port '5432'? in
|
|
/path/to/file.php on line 20.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>postmaster -i &</entry>
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
<entry>OK</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
</para>
|
|
<para>
|
|
Si può stabilire una connessione al server PostgreSQL usando le
|
|
seguenti coppie di valori impostati nella stringa di comando: <command>$conn =
|
|
pg_connect("host=IlMioHost port=LaMiaPort tty=myTTY options=LeMieOpzioni
|
|
dbname=IlMioDB user=IlMioUtente password=LaMiaPassword ");
|
|
</command>
|
|
</para>
|
|
<para>
|
|
L'uso della sintassi in uso precedentemente:
|
|
<command>
|
|
$conn = pg_connect ("host", "port", "options", "tty", "dbname")
|
|
</command>
|
|
è deprecato.
|
|
</para>
|
|
<para>
|
|
Le variabili d'ambiente influiscono sul comportamento del server/client
|
|
PostgreSQL. Per esempio, il modulo PostgreSQL userà la variabile d'ambiente
|
|
PGHOST quando l'hostname viene omesso nella stringa di
|
|
connessione. Le variabili d'ambiente supportate differiscono da versione
|
|
a versione. Fare riferimento al Manuale di Programmazione di PostgreSQL (libpq -
|
|
Environment Variables) per ulteriori dettagli.
|
|
</para>
|
|
<para>
|
|
A partire da PostgreSQL 7.1.0, il tipo di dato text ha 1GB come dimensione
|
|
massima. Nelle versioni più vecchie di PostgreSQL il tipo di dato text è limitato dalla dimensione
|
|
del block. (Default 8KB. Massimo 32KB, specificato al momento della compilazione)
|
|
</para>
|
|
<para>
|
|
Per usare l'interfaccia large object (lo), è necessario includerla entro
|
|
un blocco di una transazione. Un blocco di transazione inizia con un
|
|
comando SQL <command>begin</command> e se la
|
|
transazione è stata valida, termina
|
|
con <command>commit</command> o <command>end</command>. Se la
|
|
transazione fallisce, essa deve venire chiusa con
|
|
<command>rollback</command> o <command>abort</command>.
|
|
<example>
|
|
<title>Utilizzare Large Objects</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$database = pg_connect ("dbname=jacarta");
|
|
pg_exec ($database, "begin");
|
|
$oid = pg_locreate ($database);
|
|
echo ("$oid\n");
|
|
$handle = pg_loopen ($database, $oid, "w");
|
|
echo ("$handle\n");
|
|
pg_lowrite ($handle, "large object data");
|
|
pg_loclose ($handle);
|
|
pg_exec ($database, "commit");
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
Non chiudere la risorsa di connessione prima di aver chiuso la risorsa
|
|
large object.
|
|
</para>
|
|
</partintro>
|
|
|
|
&reference.pgsql.functions;
|
|
|
|
</reference>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|