Bonjour,
Je suis en train d'essayer de faire deux INSERT consecutifs en php dans une base postgreSQL
Je souhaite demarrer une transaction, faire une premiere insertion puis faire un select pour recuperer l'identifiant du tupple que je vien d'inserer et enfin faire une deuxieme insertion utilisant l'identifiant fraichement recupere
voici le code :
Ca plante sur le deuxieme INSERT l'erreur renvoye est la suivante ;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 pg_query($conn,"begin"); $result=pg_query($conn,$queryXtal); if (!$result){ pg_query($conn,"rollback"); echo "<font class='titley2'>Fail to insert the hit !</font>"; }else{ // Recuperation identifiants du crystal & insertion dans table Sample Drop has crystal $queryXtal = "SELECT idCrystal FROM Crystal WHERE CrystalDate='$time' AND CrystalType_idCrystalType=$crystalType AND Morphology_idMorphology=$morphology AND Structure_idStructure=$structure AND GrowthTime=$growthtime AND CrystalLength= $xtlength AND CrystalWidth=$xtwidth AND CrystalDepth=$xtdepth"; $arrayXtal = pgsql_select($conn, $queryXtal); // Fonction perso qui effectue un SELECT et renvoi un tableau a deux dimentions $idXtal = $arrayXtal[0][0]; //insert Sample_Has_drop reference $querySampleDropHasXtal = "INSERT INTO SampleDrop_Has_Crystal(Crystal_CrystalDate, Crystal_idCrystal, SampleDrop_idSampleDrop) VALUES('$time',$idXtal, $idSampleDrop)"; echo "\nQuery SampleDropHasXtal=\n".$querySampleDropHasXtal; $result1=pg_query($db,$querySampleDropHasXtal); if (!$result1){ pg_query($conn,"rollback"); echo "<font class='titley2'>Fail to insert the hit !</font>"; }else{ pg_query($conn,"commit"); echo "<font class='titley2'>New Hit saved, thanks you!</font>"; } }
j'ai pourtant tester d'inserer manuelement dans psql un echo du 2eme INSERT et ca a marche sans souci...Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /var/www/html/htxlab/hitTracking/php/model.php on line 247
Pouvez-vous m'aider?
Partager