Instancier une classe pour chaque résultat avec OCI_
aloha
Je définis ma classe :
Code:
1 2 3 4 5 6
| <?php
class AutoCompletionCPVille {
public $CodeInsee;
public $Nom;
}
?> |
Merci à x zolezzi pour son tuto sur l'autocomplétion.
Utilisant oracle, je passe plutôt par de l'OCI. Je récupère mon résultat de requête sous forme de tableau, mais je ne sais pas comment instancier chacun de mes résultats.
Comment faire ?
D'avance merci,
Ci après mon code :
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 71 72 73 74 75
| <?php
error_reporting(E_ALL || E_NOTICE);
require_once('./AutoCompletionCPVille.class.php');
function select_to_array($connexion, $select)
{
// Crée un tableau, un curseur, compte les colonnes,
// fait le fetch en insérant dans le tableau.
$myResults = array();
// ora_do analyse (ora_parse) $query, l'exécute (ora_exec)
// et lit la première ligne du résultat (ora_fetch).
$statementID = oci_parse($connexion, $select);
$executeResult = oci_execute($statementID);
while (($row = oci_fetch_array($statementID, OCI_ASSOC))) {
array_push($myResults, $row);
}
oci_free_statement($statementID);
return $myResults;
}
//Initialisation de la liste
$list = array();
//Connexion Oracle
$base = "SIGE";
try
{
//echo 'bob';
$ora_connSIGE = oci_connect("*****","$$$$$",$base);
}
catch (Exception $ex)
{
echo $ex->getMessage();
}
//Construction de la requete
$strQuery = "SELECT CO_INSEE CodeInsee, NOM Nom FROM BT_COMMU WHERE ";
if (isset($_POST["codeInsee"]))
{
$strQuery .= "CO_INSEE LIKE :codeInsee ";
}
else
{
$strQuery .= "NOM LIKE :ville ";
}
$strQuery .= "AND DEPART = 'MARNE' ";
//Limite
if (isset($_POST["maxRows"]))
{
$strQuery .= "LIMIT 0, :maxRows";
}
if (isset($_POST["co_insee"]))
{
$value = $_POST["co_insee"]."%";
oci_bind_by_name($statementID, ":codeInsee", $value);
}
else
{
$value = $_POST["ville"]."%";
oci_bind_by_name($statementID, ":ville", $value);
}
//Limite
if (isset($_POST["maxRows"]))
{
$valueRows = intval($_POST["maxRows"]);
oci_bind_by_name($statementID, ":maxRows", $value);
}
$list = select_to_array($ora_connSIGE, $strQuery);
echo json_encode($list);
?> |