Insertion d'un blob en passant par une procédure stockée
Bonjour,
Je cherche à insérer un blob dans une base Oracle en passant par une procédure stockée
PROCEDURE :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| CREATE OR REPLACE PROCEDURE Insert_Blob (
pChamp1 IN maTable.CHAMP_TEXTE1%TYPE,
pBlob IN maTable.CHAMP_BLOB%TYPE)
AS
lob_loc BLOB;
amount BINARY_INTEGER;
id INTEGER;
BEGIN
SELECT dbms_lob.GETLENGTH(pBlob) INTO amount FROM dual ;
SELECT maTable_SEQ.NEXTVAL INTO id FROM dual ;
INSERT INTO maTable
(ID, CHAMP_TEXTE1, CHAMP_BLOB)
VALUES
(id, pChamp1, EMPTY_BLOB())
RETURNING CHAMP_BLOB INTO lob_loc;
dbms_lob.WRITE (lob_loc, amount, 0, pBlob);
END Insert_Blob;
/ |
Appel PHP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| /*
* Ouverture du fichier binaire à stocker dans la table
*/
if (!$handle = fopen('image.jpg','rb')) return 0;
$contenu_fichier = fread($handle, filesize ('image.jpg'));
fclose($handle);
/*
* Clé, type, valeurs à insérer dans la table
*/
$arrVals[0]['key'] = ':pChamp1';
$arrVals[0]['type'] = 'DEFAUT';
$arrVals[0]['valeur'] = 'du texte';
$arrVals[1]['key'] = ':pBlob';
$arrVals[1]['type'] = 'BLOB';
$arrVals[1]['valeur'] = $contenu_fichier;
/*
* Insertion dans la table
*/
$stmt = OCIParse($connexion, 'BEGIN INSERT_BLOB(:pChamp1, :pBlob);END;');
$cpt = count($arrVals);
for($i=0; $i<$cpt; $i++) {
//CAS D'un BLOB
if ($arrVals[$i]["type"]== 'BLOB') {
${'BLOB'.$i} = OCINewDescriptor($connexion,OCI_D_LOB);
OCIBindByName($stmt, $arrVals[$i]["key"],${'BLOB'.$i}, -1, OCI_B_BLOB);
${'BLOB'.$i}->WriteTemporary($arrVals[$i]["valeur"], OCI_TEMP_BLOB);
}
// Cas par défaut
else if ($arrVals[$i]["type"]== 'DEFAUT') {
OCIBindByName($stmt, $arrVals[$i]["key"], $arrVals[$i]["valeur"]);
}
}
$r = OCIExecute($stmt, OCI_DEFAULT);
OCICommit($this->ptConnexion);
ocifreestatement($stmt);
for($i=0; $i<$cpt; $i++) {
if ($arrVals[$i]["type"]== 'BLOB') {
${'BLOB'.$i}->close();
${'BLOB'.$i}->free();
}
} |
Je récupére une erreur au moment de l'exécution de la procédure :
Code:
PHP Warning: OCIStmtExecute: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments
C'est quoi qui ne va pas dans ma méthode (Je travaille en PHP 4.2.3) :?:
Merci d'avance !