IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Zend PHP Discussion :

complex query with zend_db_select!


Sujet :

Zend PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 17
    Par défaut complex query with zend_db_select!
    Bonjour,

    Je suis débutant en développement php, j essaye depuis un petit moments sans succès de renvoyer un tableau a partir d une requête complexe (avec WHERE, ORDER BY, GROUP BY) en MVC sur zend framework, j ai tenté d adapter mon code a quelques exemple sur le net mais ça ne marche pas, du coup je suis vraiment bloqué sur cette partie,

    requête:
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    SELECT NY_HOSTS.HOST_NAME, NY_ISMSC_CLASSES.CLASS_NAME, NY_STATISTICS_AGG_DATA.INSTANCE, NY_OPERATIONS.DESCRIPTIONS, NY_DATA_TYPES.DISPLAY_STRING
    FROM SM_STATISTICS.NY_DATA_TYPES NY_DATA_TYPES, OMAP_CONFIG.NY_HOSTS NY_HOSTS, OMAP_CONFIG.NY_ISMSC_CLASSES NY_ISMSC_CLASSES, SM_STATISTICS.NY_OPERATIONS NY_OPERATIONS, SM_STATISTICS.NY_STATISTICS_AGG_DATA NY_STATISTICS_AGG_DATA
    WHERE ( ( NY_DATA_TYPES.TYPE_ID = NY_STATISTICS_AGG_DATA.DATA_TYPE_ID ) AND ( NY_HOSTS.HOST_ID = NY_STATISTICS_AGG_DATA.HOST_ID ) AND ( NY_ISMSC_CLASSES.CLASS_ID = NY_STATISTICS_AGG_DATA.CLASS_ID AND NY_ISMSC_CLASSES.GROUP_ID = NY_STATISTICS_AGG_DATA.GROUP_ID ) AND ( NY_OPERATIONS.CLASS_ID = NY_DATA_TYPES.CLASS_ID AND NY_OPERATIONS.OPERATION_ID = NY_DATA_TYPES.OPERATION_ID ) )
    GROUP BY NY_ISMSC_CLASSES.CLASS_NAME, NY_OPERATIONS.DESCRIPTIONS, NY_DATA_TYPES.DISPLAY_STRING, NY_HOSTS.HOST_NAME, NY_STATISTICS_AGG_DATA.INSTANCE
    ORDER BY NY_HOSTS.HOST_NAME, NY_ISMSC_CLASSES.CLASS_NAME, NY_STATISTICS_AGG_DATA.INSTANCE, NY_OPERATIONS.DESCRIPTIONS, NY_DATA_TYPES.DISPLAY_STRING

    vraiment besoin d aide, MERCI beaucoup

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Fait tes jointures comme ça :

    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SELECT colonne1, colonne2, colonne3 FROM
    table1 JOIN table2 ON clef1.table1 = clef2.table2

    Sinon dis nous ce que tu veux obtenir exactement et la ou tu en es.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre actif
    Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 17
    Par défaut
    voila en fête je voudrais renvoyer le résultat de cette requête, en tableau sous zend framework et du coup en mvc, j ai tester un oci_parse et un oci_fetch_array pour voir s il y a un résultat et j ai bien un tableau retourné, mais la j essaye de l intégrer a mon application, j essaye de renvoyer ça dans un tableau plus présentable! en utilisant zend_db_select par exemple, et je pense que ca va me faciliter après la tache pour rendre le contenu de la colonne"NY_DATA_TYPES.DISPLAY_STRING" cliquable, pour aller sur une page correspondante a la ligne sélectionné pour exécuter une autre opération, j espère que j ai exprimé correctement ce que j essaye de faire avec tout ça

  4. #4
    Membre actif
    Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 17
    Par défaut
    voila la solution*
    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
    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
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    <?php
     
    class IndicatorsController extends Oft_Controller_DatagridAbstract
    {
        protected $_title = "Indicators per Hosts & Class Instances";
     
     
        public function init()
        {
            // Identifiant de colonne
            $this->_idColumn = 'HOST_NAME';
     
     
            // Définition des options de colonnes
            $this->_columnOptions = array(
                'HOST_NAME' => 'Host Name',
                'CLASS_NAME' => 'Class Name',
                'INSTANCE' => 'Instance',
                'DESCRIPTIONS' => 'Description',
                'DISPLAY_STRING' => array('name' => 'Indicator',
                            'sortable' => false,
    			            'formatter' => 'showlink'
    	        )
            );
        }
     
     
        /**
         * Récupération de l'iterateur (simple tableau PHP)
         *
         * @see Oft_Controller_DatagridAbstract::getIterator()
         */
        public function getIterator($options)
        {
     
            $db = Oft_App::getInstance()->getResource('multidb')->getDb('oracledb');
     
     
     
    //         CCPHP : ne fonctionne pas (pour l'instant)
    //         $sql = $db->select()
    //             ->distinct()
    //             ->from(array('NY_DATA_TYPES' => 'SM_STATISTICS.NY_DATA_TYPES'), array('NY_HOSTS.HOST_NAME', 'NY_ISMSC_CLASSES.CLASS_NAME', 'NY_STATISTICS_AGG_DATA.INSTANCE', 'NY_OPERATIONS.DESCRIPTIONS', 'NY_DATA_TYPES.DISPLAY_STRING'))
    //             ->join(array('NY_STATISTICS_AGG_DATA' => 'SM_STATISTICS.NY_STATISTICS_AGG_DATA'), 'NY_DATA_TYPES.TYPE_ID = NY_STATISTICS_AGG_DATA.DATA_TYPE_ID')
    //             ->join(array('NY_HOSTS' => 'OMAP_CONFIG.NY_HOSTS'), 'NY_HOSTS.HOST_ID = NY_STATISTICS_AGG_DATA.HOST_ID')
    //             ->join(array('NY_ISMSC_CLASSES' => 'OMAP_CONFIG.NY_ISMSC_CLASSES'), ('NY_ISMSC_CLASSES.CLASS_ID = NY_STATISTICS_AGG_DATA.CLASS_ID AND NY_ISMSC_CLASSES.GROUP_ID = NY_STATISTICS_AGG_DATA.GROUP_ID'))
    //             ->join(array('NY_OPERATIONS' => 'SM_STATISTICS.NY_OPERATIONS'), 'NY_OPERATIONS.CLASS_ID = NY_DATA_TYPES.CLASS_ID AND NY_OPERATIONS.OPERATION_ID = NY_DATA_TYPES.OPERATION_ID')
    //             ->order(array('NY_HOSTS.HOST_NAME', 'NY_ISMSC_CLASSES.CLASS_NAME', 'NY_STATISTICS_AGG_DATA.INSTANCE', 'NY_OPERATIONS.DESCRIPTIONS', 'NY_DATA_TYPES.DISPLAY_STRING'))
    //             ;
     
    //         return $sql;
     
    //         CCPHP : PAS IDEAL car tous les enregistrements sont récupérés
    //         SOLUTION : utiliser Zend_Db_Select
            $sql = '
     SELECT DISTINCT
      NY_HOSTS.HOST_NAME,
      NY_ISMSC_CLASSES.CLASS_NAME,
      NY_STATISTICS_AGG_DATA.INSTANCE,
      NY_OPERATIONS.DESCRIPTIONS,
      NY_DATA_TYPES.DISPLAY_STRING
    FROM
      SM_STATISTICS.NY_DATA_TYPES NY_DATA_TYPES
    INNER JOIN
      SM_STATISTICS.NY_STATISTICS_AGG_DATA NY_STATISTICS_AGG_DATA
      ON NY_DATA_TYPES.TYPE_ID = NY_STATISTICS_AGG_DATA.DATA_TYPE_ID
    INNER JOIN
      OMAP_CONFIG.NY_HOSTS NY_HOSTS
      ON NY_HOSTS.HOST_ID = NY_STATISTICS_AGG_DATA.HOST_ID
    INNER JOIN
      OMAP_CONFIG.NY_ISMSC_CLASSES NY_ISMSC_CLASSES
      ON (
        NY_ISMSC_CLASSES.CLASS_ID = NY_STATISTICS_AGG_DATA.CLASS_ID AND NY_ISMSC_CLASSES.GROUP_ID = NY_STATISTICS_AGG_DATA.GROUP_ID
      )
    INNER JOIN
      SM_STATISTICS.NY_OPERATIONS NY_OPERATIONS
      ON (
        NY_OPERATIONS.CLASS_ID = NY_DATA_TYPES.CLASS_ID AND NY_OPERATIONS.OPERATION_ID = NY_DATA_TYPES.OPERATION_ID
      )
    WHERE 1=1
            
    ORDER BY NY_HOSTS.HOST_NAME,
      NY_ISMSC_CLASSES.CLASS_NAME,
      NY_STATISTICS_AGG_DATA.INSTANCE,
      NY_OPERATIONS.DESCRIPTIONS,
      NY_DATA_TYPES.DISPLAY_STRING
            ';
     
     
     
     
            $result = $db->query($sql)->fetchAll();
     
     
     
            return $result;
        }
     
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 19
    Dernier message: 30/05/2015, 17h10
  2. Crosstab query with Toad for Oracle
    Par frade dans le forum Décisions SGBD
    Réponses: 3
    Dernier message: 30/08/2009, 14h35
  3. PHP query with DB package PEAR
    Par taki.said dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 10/02/2009, 07h21
  4. [BUG] Zend_Db_Select query method
    Par sekaijin dans le forum Zend_Db
    Réponses: 2
    Dernier message: 13/10/2007, 17h19
  5. Not Like --> Query is Too Complex
    Par stefposs dans le forum Requêtes et SQL.
    Réponses: 6
    Dernier message: 17/09/2007, 17h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo