Consultation des donnees oracle via PHP

Fermé
bfiguig - 3 déc. 2008 à 09:04
 bfiguig - 3 déc. 2008 à 14:52
Bonjour à tous,
j'essaye de faire un select dans des tables d'une base oracle.
j'utilise :

oci_parse; oci_execute; oci_fetch; oci_result

mon probleme c'est que je n'arrive pas à tester si tel champs est vide ou pas
voila une partie de mon code:

$schema = oci_parse($conn, "SELECT * FROM SCHEMA WHERE ID_DATABASE = '".$ID_DATABASE_value."'");

oci_execute($schema);
while (oci_fetch($schema))
{
print '<TD>' . oci_result($sgbd, 1) . '</TD>';
}

je voudrai tester si tel champ est vide j'affiche ca :
print '<TD>  </TD>';

en resumé, comment verifier tel ligne ou tel colonne existe ou pas
merci d'avance
cordialement

3 réponses

pitxu Messages postés 689 Date d'inscription vendredi 7 septembre 2007 Statut Membre Dernière intervention 25 mars 2015 94
3 déc. 2008 à 10:25
bonjour,

c'est le problème de l'utilisation de la boucle while (="tant que"), dès que la condition n'est plus vraie, elle s'arrête.

On peut tricher avec un if/else :

while (oci_fetch($schema))
{
if (oci_result($sgbd, 1)=="") { oci_result($sgbd, 1)=" "; }
print '<TD>' . oci_result($sgbd, 1) . '</TD>';
}

Essaie ça et dis moi si ça marche ;)
0
Re-bonjour,
il m'affiche un message d'erreur:

Fatal error: Can't use function return value in write context in C:\wamp\www\ecran\base.php on line 275
la ligne 275 corresponde à : oci_result($schema, 2)=" ";
merci
0
pitxu Messages postés 689 Date d'inscription vendredi 7 septembre 2007 Statut Membre Dernière intervention 25 mars 2015 94
3 déc. 2008 à 12:56
ton code fait-il partie d'une fonction ? si oui post la fonction complète stp
0
merci de ton aide
voici le code en php

<?php
$conn = oci_connect("DBAR_ADMIN_BEN", "bfiguig1", "pdbar1_proradba1");

$stmt = oci_parse($conn, "SELECT LIBELLE, ID_SGBD, VERSION, ID_SERVEUR, MUTUALISE, PORT, CHARSET, TYPE_SAUVEGARDE, ID_DATABASE FROM DATABASE WHERE MUTUALISE = '".$mutualise."' and LIBELLE like '".$libelle."%' and VERSION like '".$version."%'");

oci_execute($stmt);

print '<table cellspacing="0" cellpadding="0" width="90%" border="1" align="center">';
print '<TR>';
print '<TD>BASE / INSTANCE</TD>';
print '<TD>SGBD</TD>';
print '<TD>VERSION</TD>';
print '<TD>SERVEUR</TD>';
print '<TD>MUTUALISE</TD>';
print '<TD>PORT</TD>';
print '<TD>CHARSET</TD>';
print '<TD>SAUVEGARDE</TD>';
print '<TD>SCHEMAS</TH>';
print '<TD>APPLICATIONS</TD>';
print '</TR>';


while (ocifetch($stmt))
{
$SGBD_value = oci_result($stmt, 2);
$SERVEUR_value = ociresult($stmt, 4);
$ID_DATABASE_value = ociresult($stmt, 9);

$ID_CHARSET_value = ociresult($stmt, 7);

$sgbd = oci_parse($conn, "SELECT LIBELLE FROM SGBD WHERE ID_SGBD = '".$SGBD_value."'");
oci_execute($sgbd);

$serveur = oci_parse($conn, "SELECT LIBELLE FROM SERVEUR WHERE ID_SERVEUR = '".$SERVEUR_value."'");
oci_execute($serveur);

$schema = oci_parse($conn, "SELECT s.ID_SCHEMA, s.LIBELLE FROM SCHEMA s, SCHEMA_DATABASE sc WHERE sc.ID_SCHEMA = s.ID_SCHEMA AND sc.ID_DATABASE = '".$ID_DATABASE_value."'");
oci_execute($schema);

print '<TR>';
print '<TD>' . ociresult($stmt, 1) . '</TD>';
while (ocifetch($sgbd))
{
print '<TD>' . ociresult($sgbd, 1) . '</TD>';
}
print '<TD>' . ociresult($stmt, 3) . '</TD>';

while (ocifetch($serveur))
{
print '<TD><a href="javascript:affiche_serveur()"><font color="#AF0635" style="FONT-WEIGHT: bold; FONT-SIZE: 11px"><span id="nom_serveur">'. ociresult($serveur, 1) .'</span></font></a></TD>';
}
print '<TD>' . ociresult($stmt, 5) . '</TD>';
print '<TD>' . ociresult($stmt, 6) . '</TD>';

if (!ociresult($stmt, 7))
{
print '<TD>  </TD>';
}
else
{
print '<TD>' . ociresult($stmt, 7) . '</TD>';
}

if (!ociresult($stmt, 8))
{
print '<TD>  </TD>';
}
else
{
print '<TD>' . ociresult($stmt, 8) . '</TD>';
}

while (ocifetch($schema))
{
$ID_SCHEMA_value = ociresult($schema, 1);

if (ociresult($schema, 2)=="")
{
print '<TD>  </TD>';
}
print '<TD><a href="javascript:affiche_schema()"><font color="#AF0635" style="FONT-WEIGHT: bold; FONT-SIZE: 11px"><span id="nom_serveur">'. ociresult($schema, 2) .'</span></font></a></TD>';
}

$application = oci_parse($conn, "SELECT a.LIBELLE FROM SCHEMA s, APPLICATION a WHERE s.ID_APPLICATION = a.ID_APPLICATION AND s.ID_SCHEMA = '".$ID_SCHEMA_value."'");
oci_execute($application, OCI_DEFAULT);

while (ocifetch($application))
{
if (ociresult($application, 1) != '')
{
print '<TD><a href="javascript:affiche_application()"><font color="#AF0635" style="FONT-WEIGHT: bold; FONT-SIZE: 11px"><span id="nom_serveur">'. ociresult($application, 1) .'</span></font></a></TD>';
}
else
{
print '<TD>  </TD>';
}
}
print '</TR>';
}
print '</table>';


oci_free_statement($stmt);
oci_close($conn);
?>
0
pitxu Messages postés 689 Date d'inscription vendredi 7 septembre 2007 Statut Membre Dernière intervention 25 mars 2015 94
3 déc. 2008 à 14:15
if (ociresult($schema, 2)=="")
{
print '<TD> </TD>';
}
print '<TD><a href="javascript:affiche_schema()"><font color="#AF0635" style="FONT-WEIGHT: bold; FONT-SIZE: 11px"><span id="nom_serveur">'. ociresult($schema, 2) .'</span></font></a></TD>';

ne serait-ce pas plutot :

if (ociresult($schema, 2)=="")
{
print '<TD> </TD>';
}
else
{
print '<TD><a href="javascript:affiche_schema()"><font color="#AF0635" style="FONT-WEIGHT: bold; FONT-SIZE: 11px"><span id="nom_serveur">'. ociresult($schema, 2) .'</span></font></a></TD>';
}
0
re-bonjour,
meme si je rajoute le else ca change rien
merci de ton aide
0