Précédent   Forum du club des développeurs et IT Pro > PHP > PHP & SGBD > PHP & Oracle
PHP & Oracle Forum d'entraide sur Oracle avec PHP. Avant de poster -> FAQ Oracle et Cours Oracle
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 04/02/2012, 15h40   #1
seb76250
Candidat au titre de Membre du Club
 
Inscription : avril 2008
Messages : 52
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 52
Points : 11
Points : 11
Par défaut Tableau en paramètre d'une requete

Bonjour,

Je voulais savoir si il était possible de passer un array php dans une requete qui exécute une procédure stockée.

Voici la procédure :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
CREATE OR REPLACE TYPE ARRAY_INT IS TABLE of number;
CREATE OR REPLACE PROCEDURE utiinsert
(
p_utinom IN VARCHAR2, p_utiprenom IN VARCHAR2, p_utilogin IN VARCHAR2, p_utimdp IN VARCHAR2, p_utimail IN VARCHAR2, p_utitel VARCHAR2, p_utiprof IN NUMBER, p_utifonc IN ARRAY_INT
)
IS
v_utiid varchar2(50);
BEGIN
INSERT INTO utilisateur 
(utiid, profid, utinom, utiprenom, utilogin, utimdp, utimail, utitel, utisuppr) 
VALUES
 (S_UTILISATEUR.NEXTVAL, p_utiprof, p_utinom, p_utiprenom, p_utilogin, p_utimdp, p_utimail, p_utitel, 0) returning utiid into v_utiid;
FORALL i IN p_utifonc.FIRST..p_utifonc.LAST
        INSERT INTO FONC_UTI(utiid, foncid) VALUES(v_utiid, p_utifonc(i));
END;
L'exécution via un client oracle :

Code :
1
2
 
exec utiinsert('nomtest2', 'prenomtest2', 'logintest2', 'mdptest2', 'mailtest2', 'teltest2', 1, ARRAY_INT(1, 21));
Comme cela ça fonctionne. Maintenant je voudrais exécuter cette procédure depuis php via pdo :

Code 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
 
<?php
$utinom = "toto";
$utiprenom = "titi";
$utilogin = "log";
$utimdp = "mdp";
$utimail = "monmail@gmail.com";
$utitel = "0654343232";
$utiprof = 1;
$utifonc = array(
21
);
$tns = " 
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
";
$db_username = "fil";
$db_password = "rouge";
try{
    $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}
$stmt = $conn->prepare("exec utiinsert(:utinom, :utiprenom, :utilogin, :utimdp, :utimail, :utitel, :utiprof, :utifonc");
$stmt->bindParam(':utinom', $utinom);
$stmt->bindParam(':utiprenom', $utiprenom);
$stmt->bindParam(':utilogin', $utilogin);
$stmt->bindParam(':utimdp', $utimdp);
$stmt->bindParam(':utimail', $utimail);
$stmt->bindParam(':utitel', $utitel);
$stmt->bindParam(':utiprof', $utiprof);
$stmt->bindParam(':utifonc', $utifonc[]);
$stmt->execute();
$errInfo = $stmt->errorInfo();
print_r($errInfo);
?>
J'obtiens l'erreur :

Code :
1
2
Array ( [0] => HY000 [1] => 900 [2] => OCIStmtExecute: ORA-00900: instruction SQL non valide (ext\pdo_oci\oci_statement.c:148) )
Est-ce que c'est possible de passer un tableau en paramètre svp ?
Fichiers attachés
Type de fichier : sql base_fil_rouge.sql (31,5 Ko, 0 affichages)
seb76250 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/02/2012, 16h25   #2
seb76250
Candidat au titre de Membre du Club
 
Inscription : avril 2008
Messages : 52
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 52
Points : 11
Points : 11
Par défaut Résolue

Bon bah quand on cherche ... on trouve !!!

Voici le code php si ça peut aider d'autres personnes :

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
<?php
function arrayFormat(&$array)
{
$str = '';
$i = 0;
$count = count($array);
foreach($array as $k=>$v)
    {
		$i = $i + 1;
		if($i == $count)
		{
			$str .= $v;
		}
		else
		{
			$str .= $v.',';
		}
    }
	echo $str;
	return $str;
}
$utinom = "testDernierUtilisateur";
$utiprenom = "jjjjjj";
$utilogin = "log";
$utimdp = "mdp";
$utimail = "monmail@gmail.com";
$utitel = "0654343232";
$utiprof = 1;
$utifonc = array(
1,
21
);
$utifonc = arrayFormat($utifonc);
$tns = " 
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
";
$db_username = "fil";
$db_password = "rouge";
try{
    $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}
$stmt = $conn->prepare("call utiinsert(:utinom, :utiprenom, :utilogin, :utimdp, :utimail, :utitel, :utiprof, ARRAY_INT($utifonc))");
$stmt->bindParam(':utinom', $utinom);
$stmt->bindParam(':utiprenom', $utiprenom);
$stmt->bindParam(':utilogin', $utilogin);
$stmt->bindParam(':utimdp', $utimdp);
$stmt->bindParam(':utimail', $utimail);
$stmt->bindParam(':utitel', $utitel);
$stmt->bindParam(':utiprof', $utiprof);
$stmt->execute();
$errInfo = $stmt->errorInfo();
echo '<pre>';
print_r($errInfo);
echo '<pre>';
$sth = $conn->prepare("SELECT * FROM utilisateur");
$sth->execute();
echo '<pre>';
print_r($sth->fetchAll());
echo '</pre>';
?>
DSL pour le dérangement
seb76250 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 03h12.


 
 
 
 
Partenaires

Hébergement Web