Skip to content

Instantly share code, notes, and snippets.

@celsowm
Created June 3, 2019 03:40
Show Gist options
  • Save celsowm/5bad06f0a9a6977876b153d5f2d9d453 to your computer and use it in GitHub Desktop.
Save celsowm/5bad06f0a9a6977876b153d5f2d9d453 to your computer and use it in GitHub Desktop.
blob pdo
<?php
include '../conexao_postgres.php';
$fotos = [
1 => 'Lurdes Boça',
2 => 'Wallace Guilhermino',
3 => 'Edson Wander',
4 => 'Cláudio Ricardo',
5 => 'Neo Labaque',
6 => 'Renato Noiadão',
7 => 'José Canjica Martins',
8 => 'Carlos Calhorda',
9 => 'Chaves',
10 => 'Sou Hype'
];
try {
foreach ($fotos as $key => $value) {
$arquivo = 'fotos' . DIRECTORY_SEPARATOR . "$key.jpg";
$binario = file_get_contents($arquivo);
$stmt = $pdo->prepare("UPDATE funcionario SET foto = :foto WHERE nome = :id");
switch ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'sqlsrv':
$stmt->bindParam(1, $binario, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
break;
case 'oci':
$stmt->bindValue(1, fopen($arquivo, "r"), PDO::PARAM_LOB);
break;
default:
$stmt->bindParam(1, $binario, PDO::PARAM_LOB);
break;
}
$stmt->bindValue(2, $value, PDO::PARAM_STR);
$stmt->execute();
}
} catch (\Throwable $ex) {
var_dump($ex->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment