Skip to content

Instantly share code, notes, and snippets.

@roskoff
Created May 3, 2011 21:43
Show Gist options
  • Save roskoff/954328 to your computer and use it in GitHub Desktop.
Save roskoff/954328 to your computer and use it in GitHub Desktop.
Exporta documentos del tipo "large object" almacenados en una base de datos PostgreSQL
<?php
// Datos de la conexion
$database = pg_connect("host='192.168.0.100' dbname='database' user='codusr' password='pass'");
// Para utilizar pg_lo_export(), debemos llamarla dentro de un transaction block
pg_query($database, "begin");
// Consulta SQL, documento es de tipo lo (large object)
$result = pg_query($database, "SELECT documento, nombre_en_disco from tabla_de_documentos");
while($row = pg_fetch_row($result)){
list($oid, $nombre) = $row;
echo "Documento: " . $nombre . " ---> ";
if(pg_lo_export($database, $oid, "/tmp/documentos/$nombre")){
echo "Exportado.<br>";
}else {
echo "NO Exportado.<br>";
}
}
// Confirmamos la transaccion
pg_query($database, "commit");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment