All pastes #640491 Raw Edit

Someone

public text v1 · immutable
#640491 ·published 2007-07-31 12:57 UTC
rendered paste body
#!/usr/bin/php5

<?php

define('_DEBUG_', true);

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              CLOB                            not null,
		RAW_DATA             NVARCHAR2(255)                  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 ?");

	$fp = file_get_contents($_SERVER['argv'][1], 'rb');

	if ($fp)
	{
	//	debug_msg($fp);
	}
	else
	{
		debug_msg('file was not : OK');
	}
	
//	$stmt->bindParam(':InsertDate', date('11/12/1981'));
	$stmt->bindParam(1, $fp, PDO::PARAM_LOB);

	$connexion->beginTransaction();

	debug_msg('Creation de la requete : ');
	debug_msg(&$stmt);

	if(! $stmt->execute() )
	{
		debug_msg('La requete a merdé : ');
		debug_msg($connexion->errorInfo());
	}

	
	debug_msg('Exec de la requete : ');
	debug_msg($stmt);

	$connexion->commit();
	debug_msg('Fin et commit');
	debug_msg(&$connexion);

} 
catch (Exception $e) 
{
	$connexion->rollBack();
	echo "Failed: " . $e->getMessage();
}


?>