0
I’m using postgresql as sgdb, and I’m saving files. txt in bd, so far, all right, it’s working right, but I’m not finding a way to get the content 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 wide_object
I am saving the txt file in the database like this:
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 this txt I saved? whatever the shape, either by sql or by php.
Are you saving the path to the file? to the content? why I noticed is the path, can you confirm? | The variable
$conteudo
is used where?– Guilherme Lautert
@Guilhermelautert not, I am not saving the way, save only the file, normally; but what would be the importance of saving the way? since the file is on my machine and will be accessed by qq person online?
– alexandre9865
Not just that, you should save the content, so I thought you were saving on the way, then it wouldn’t result in what you want. This column is of what type? you checked in pgadmin if it is populated?
– Guilherme Lautert
@Guilhermelautert the column is of type oid, it is a type used for large Bjects, basically it is a number that references the file, which is stored in a place separate from the database of the system itself, and the code that I have put there is establishing certinho, I just put it there in an attempt to make you understand the dynamics of what I need
– alexandre9865
what I really need is to export the contents of this file saved in the bd
– alexandre9865