#!/usr/bin/php5
<?php
define('_DEBUG_', FALSE);
function debug_msg( $msg )
{
if (_DEBUG_)
{
if (is_string($msg))
{
echo "\nDebug : $msg\n";
}
else
{
var_dump($msg);
}
}
}
/* This first if is there to make sure that there are exactly two arguments.
* The first argument would be "backup.php" because thats the name of the script,
* The second argument would be the directory name that they want to back up
*/
if($_SERVER['argc'] != 2)
{
echo "\n\npepsise_up.sh needs one argument : usage </directory/file.ext>\n\n";
die();
}
else
{
debug_msg('arguments checked and are OK');
}
/* This tests to see if the file really exists using file_exists()
* And that its a directory using is_dir(), if the file doesn't exist
* or isn't a directory, it would die with an error
*/
if(!file_exists($_SERVER['argv'][1]))
{
die("\n\n".$_SERVER['argv'][1] . " is not a valid directory/file\n\n");
}
{
debug_msg('file check was OK');
}
/*
* This tries to connect to oracle using the /etc/pepsise/orc.ini
*/
try
{
$connexion = new PDO("oci:host=vanves5;dbname=DEV9.WORLD", "PEPSISEDEV", "sise2007");
debug_msg("Connection was : OK");
debug_msg($connexion);
}
catch(PDOException $e)
{
echo ($e->getMessage());
die("\n\nImpossible to connext to oracle, exited!\n\n");
}
/*
* this inserts the images in the database
create table PEPSISE_FICHIER_BRUT (
ID_FICHIER_BRUT NUMBER(6) not null,
FK_SF__CODE_CHAMP VARCHAR2(10),
FK_PEP_ID_CONTROLE_CAMPAGNE NUMBER(6),
FK_E_M_ID_E_MAIL NUMBER(6),
FK_DOC_ID_DOCUMENT NUMBER(6),
RAW_NOM NVARCHAR2(255) not null,
RAW_DATA BLOB not null,
RAW_DATE_CREA DATE not null,
constraint PK_PEPSISE_FICHIER_BRUT primary key (ID_FICHIER_BRUT)
*
*/
try
{
$stmt = $connexion->prepare("
INSERT INTO
PEPSISE_FICHIER_BRUT
VALUES
(
S_PEPSISE_FICHIER_BRUT.nextval,
'1',
'',
'',
'',
'testOliver',
EMPTY_BLOB(),
'11/12/1981'
)
RETURNING RAW_DATA INTO :myblob");
if ($fp)
{
debug_msg($fp);
}
else
{
debug_msg('file was not : OK');
}
$fp = file_get_contents($_SERVER['argv'][1]);
$stmt->bindParam(":myblob", $fp, PDO::PARAM_LOB);
debug_msg('Creation de la requete : ');
debug_msg($stmt);
if($stmt->execute( /* array($fp */))
{
debug_msg('La requete a merdé : ');
debug_msg($connexion->errorInfo());
}
$connexion->beginTransaction();
$connexion->commit();
debug_msg('Fin et commit');
debug_msg(&$connexion);
}
catch (Exception $e)
{
$connexion->rollBack();
echo "Failed: " . $e->getMessage();
}
?>