How do I get a file from within the database?

0

I'm using postgresql as sgdb, and I'm saving .txt files in bd, so far, all right, it's already working fine, but I'm not finding a way to get the contents of the txt files saved in bd, I'm using php with PDO for connection to bd

The type of column that saves txt in the database is OID, which stores a large_object

I'm saving the txt file in the database:

session_start();
require 'database.php';

$n_documento    = (!empty($_POST['documento']))     ? $_POST['documento']       : '';
$n_capitulo     = (!empty($_POST['capitulo']))      ? $_POST['capitulo']        : '';
$titulo         = isset($_POST['titulo'])           ? $_POST['titulo']          : '';
$paragrafo      = isset($_POST['valor_paragrafo'])  ? $_POST['valor_paragrafo'] : '';

$fp = fopen("capitulo_$n_capitulo.txt", "w+");
$conteudo = fwrite($fp, $paragrafo);
fclose($fp);
if(!empty($_POST)) {
    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "UPDATE capitulos SET
                paragrafo = lo_import('C:/wamp/www/crud/capitulo_$n_capitulo.txt'),
                titulo = $titulo
            WHERE id_documento = $n_documento
                  AND n_capitulo = $n_capitulo";
    $pdo->query($sql);
    Database::disconnect();
}

How do I get the txt I saved? either by form or by sql or by php.

    
asked by anonymous 30.03.2016 / 00:48

0 answers