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

Bases de données Delphi Discussion :

[MySQL]Aide à un débutant


Sujet :

Bases de données Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Août 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 35
    Par défaut [MySQL]Effectuer un insert avec Delphi for PHP
    Bonjour, étant débutant en Delphi, et pas très doué en programmation, après avoir silloné le net, je me rabat sur vous.

    Je dois développer sous Delphi for PHP, et déjà au départ j'ai quelque problème pour mes requêtes. J'ai installé EasyPhp afin de m'entrainer et d'avoir un serveur apache et une base Mysql sous la main.

    J'essaye de créer un "insert" en utilisant le "query" (je ne connais même pas le mot pour désigner le navigateur à côté, pour vous dire à quel point je suis une cloche) mais quand je met cette requête dans le champ:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    insert into hihi('id','name') values (9, 'hoho')
    j'ai une erreur qui me donne:

    Application raised an exception class ADODB_Exception with message 'mysql error: [1064: Erreur de syntaxe près de ''id','name') values (9, 'hoho') LIMIT 0,10' à la ligne 1] in EXECUTE("insert into hihi('id','name') values (9, 'hoho') LIMIT 0,10")
    '
    Callstack #0 File: C:\Documents and Settings\Treunet\Mes documents\Delphi for PHP Projects\training\Last\unit_datamodule.php Line: 28
    |_Callstack #1 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 1213
    |_Callstack #2 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 1243
    |_Callstack #3 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 489
    |_Callstack #4 File: Line:
    |_Callstack #5 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 415
    |_Callstack #6 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 846
    |_Callstack #7 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 510
    |_Callstack #8 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 1117
    |_Callstack #9 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 693
    |_Callstack #10 File: C:\program files\CodeGear\delphi for php\1.0\vcl\system.inc.php Line: 190
    |_Callstack #11 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 1089
    |_Callstack #12 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 1136
    |_Callstack #13 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 933
    |_Callstack #14 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 924
    |_Callstack #15 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 576
    |_Callstack #16 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 179
    |_Callstack #17 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\drivers\adodb-mysql.inc.php Line: 490
    |_Callstack #18 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\adodb.inc.php Line: 882
    |_Callstack #19 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\adodb.inc.php Line: 907



    Et si je retire les ' pour les paramètres, j'ai:

    hihi

    Application raised an exception class ADODB_Exception with message 'mysql error: [1064: Erreur de syntaxe près de 'LIMIT 0,10' à la ligne 1] in EXECUTE("insert into hihi(id,name) values (9, hoho) LIMIT 0,10")
    '
    Callstack #0 File: C:\Documents and Settings\Treunet\Mes documents\Delphi for PHP Projects\training\2\unit6.php Line: 35
    |_Callstack #1 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 1213
    |_Callstack #2 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 1243
    |_Callstack #3 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 489
    |_Callstack #4 File: Line:
    |_Callstack #5 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 415
    |_Callstack #6 File: C:\program files\CodeGear\delphi for php\1.0\vcl\classes.inc.php Line: 846
    |_Callstack #7 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 510
    |_Callstack #8 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 1117
    |_Callstack #9 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 693
    |_Callstack #10 File: C:\program files\CodeGear\delphi for php\1.0\vcl\system.inc.php Line: 190
    |_Callstack #11 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 1089
    |_Callstack #12 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 1136
    |_Callstack #13 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 933
    |_Callstack #14 File: C:\program files\CodeGear\delphi for php\1.0\vcl\db.inc.php Line: 924
    |_Callstack #15 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 576
    |_Callstack #16 File: C:\program files\CodeGear\delphi for php\1.0\vcl\dbtables.inc.php Line: 179
    |_Callstack #17 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\drivers\adodb-mysql.inc.php Line: 490
    |_Callstack #18 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\adodb.inc.php Line: 882
    |_Callstack #19 File: C:\program files\CodeGear\delphi for php\1.0\vcl\adodb\adodb.inc.php Line: 907
    Pouvez-vous m'aider svp à me dire où est mon erreur?

  2. #2
    Membre chevronné Avatar de AL1986
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    434
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 434
    Par défaut
    Citation Envoyé par truebison
    Et si je retire les ' pour les paramètres, j'ai:
    C'est à dire ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    insert into hihi(id,name) values (9, 'hoho')
    ou ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    insert into hihi(id,name) values (9, hoho)
    parce que ton erreur suggèrerait plutôt la deuxième écriture que j'estime être erronée.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Août 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 35
    Par défaut
    En fait, je sais que la 2e proposition n'est pas correct, mais ce relevé d'erreur fait partie d'une série de test que j'ai effectué à un moment car ça me précisais qu'il y avait une erreur à chaque fois avant les guillemets. Mais j'ai essayé toutes les écritures possibles, comprenant ou pas les '.

  4. #4
    Membre chevronné Avatar de AL1986
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    434
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 434
    Par défaut
    Peux-tu envoyer le code Delphi que tu exécutes ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Août 2007
    Messages
    35
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 35
    Par défaut
    j'imagine qu'il faut que je mette également le fichier xml, sinon ça n'aura pas grand sens (du moins, je le pense, j'ai remarqué que c'est là que se trouve toutes les données)

    Pour la fiche principale:
    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
    <?php
            //Includes
            require_once("vcl/vcl.inc.php");
            require_once("unit_datamodule.php");
            use_unit("dbgrids.inc.php");
            use_unit("forms.inc.php");
            use_unit("extctrls.inc.php");
            use_unit("stdctrls.inc.php");
     
            //Class definition
            class Unit1 extends Page
            {
                   public $DBGrid1 = null;
            }
     
            global $application;
     
            global $Unit1;
     
            //Creates the form
            $Unit1=new Unit1($application);
     
            //Read from resource file
            $Unit1->loadResource(__FILE__);
     
            //Shows the form
            $Unit1->show();
     
    ?>
    Le fichier xml de la fiche principale:
    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
    <?php
    <object class="Unit1" name="Unit1" baseclass="page">
      <property name="Background"></property>
      <property name="Caption">Unit1</property>
      <property name="DocType">dtNone</property>
      <property name="Font">
        <property name="Align">taNone</property>
        <property name="Case"></property>
        <property name="Color"></property>
        <property name="Family">Verdana</property>
        <property name="LineHeight"></property>
        <property name="Size">10px</property>
        <property name="Style"></property>
        <property name="Variant"></property>
        <property name="Weight"></property>
      </property>
      <property name="Height">600</property>
      <property name="IsMaster">0</property>
      <property name="Layout">
        <property name="Cols">5</property>
        <property name="Rows">5</property>
        <property name="Type">ABS_XY_LAYOUT</property>
      </property>
      <property name="Name">Unit1</property>
      <property name="Width">800</property>
      <property name="OnAfterShow"></property>
      <property name="OnAfterShowFooter"></property>
      <property name="OnBeforeShow"></property>
      <property name="OnBeforeShowHeader"></property>
      <property name="OnCreate"></property>
      <property name="OnShow"></property>
      <property name="OnShowHeader"></property>
      <property name="OnStartBody"></property>
      <property name="OnTemplate"></property>
      <object class="DBGrid" name="DBGrid1" >
        <property name="DataSource">Unit2.dshihi1</property>
        <property name="Font">
            <property name="Align">taNone</property>
            <property name="Case"></property>
            <property name="Color"></property>
            <property name="Family">Verdana</property>
            <property name="LineHeight"></property>
            <property name="Size">10px</property>
            <property name="Style"></property>
            <property name="Variant"></property>
            <property name="Weight"></property>
        </property>
        <property name="Height">200</property>
        <property name="Left">254</property>
        <property name="Name">DBGrid1</property>
        <property name="Top">373</property>
        <property name="Width">400</property>
        <property name="OnAfterShow"></property>
        <property name="OnBeforeShow"></property>
        <property name="OnShow"></property>
        <property name="jsOnRowChanged"></property>
        <property name="jsOnRowSaved"></property>
      </object>
    </object>
    ?>


    Le data module:
    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
    <?php
            require_once("vcl/vcl.inc.php");
            //Includes
            require_once("fiche_princ.php");
            use_unit("db.inc.php");
            use_unit("dbtables.inc.php");
            use_unit("forms.inc.php");
            use_unit("extctrls.inc.php");
            use_unit("stdctrls.inc.php");
     
            //Class definition
            class Unit2 extends DataModule
            {
                   public $Query1 = null;
                   public $dshihi1 = null;
                   public $dbmysql1 = null;
            }
     
            global $application;
     
            global $Unit2;
     
            //Creates the form
            $Unit2=new Unit2($application);
     
            //Read from resource file
            $Unit2->loadResource(__FILE__);
     
    ?>
    Le fichier xml du module:
    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
    <?php
    <object class="Unit2" name="Unit2" baseclass="datamodule">
      <property name="Height">600</property>
      <property name="Name">Unit2</property>
      <property name="Width">800</property>
      <property name="OnAfterShow"></property>
      <property name="OnBeforeShow"></property>
      <property name="OnShow"></property>
      <object class="Table" name="tbhihi1" >
            <property name="Left">392</property>
            <property name="Top">222</property>
        <property name="Database">dbmysql1</property>
        <property name="MasterFields">a:0:{}</property>
        <property name="MasterSource"></property>
        <property name="Name">tbhihi1</property>
        <property name="TableName">hihi</property>
        <property name="OnAfterCancel"></property>
        <property name="OnAfterClose"></property>
        <property name="OnAfterDelete"></property>
        <property name="OnAfterEdit"></property>
        <property name="OnAfterInsert"></property>
        <property name="OnAfterOpen"></property>
        <property name="OnAfterPost"></property>
        <property name="OnBeforeCancel"></property>
        <property name="OnBeforeClose"></property>
        <property name="OnBeforeDelete"></property>
        <property name="OnBeforeEdit"></property>
        <property name="OnBeforeInsert"></property>
        <property name="OnBeforeOpen"></property>
        <property name="OnBeforePost"></property>
        <property name="OnDeleteError"></property>
      </object>
      <object class="Database" name="dbmysql1" >
            <property name="Left">64</property>
            <property name="Top">222</property>
        <property name="Connected">1</property>
        <property name="DatabaseName">mysql</property>
        <property name="Dictionary"></property>
        <property name="DriverName">mysql</property>
        <property name="Host">localhost:3306</property>
        <property name="Name">dbmysql1</property>
        <property name="UserName">testeur</property>
        <property name="UserPassword">test</property>
        <property name="OnAfterConnect"></property>
        <property name="OnAfterDisconnect"></property>
        <property name="OnBeforeConnect"></property>
        <property name="OnBeforeDisconnect"></property>
      </object>
      <object class="Datasource" name="dshihi1" >
            <property name="Left">256</property>
            <property name="Top">238</property>
        <property name="Dataset">Query1</property>
        <property name="Name">dshihi1</property>
      </object>
      <object class="Query" name="Query1" >
            <property name="Left">147</property>
            <property name="Top">233</property>
        <property name="Active">1</property>
        <property name="Database">dbmysql1</property>
        <property name="Name">Query1</property>
        <property name="Params">a:0:{}</property>
        <property name="SQL"><![CDATA[a:1:{i:0;s:44:&quot;insert into hihi(id,name) values (9, 'hoho')&quot;;}]]></property>
        <property name="TableName">hihi</property>
      </object>
    </object>
    ?>
    En espérant que ça puisse te servir

    Encore, je serais dans un univers entièrement PHP, j'aurais pus me débrouiller mais là, j'ai passé tout le week end dessus, et je ne trouve pas

    Ah oui, il faut que je précise qu'une requête du style "select" passe sans prob.

  6. #6
    Membre chevronné Avatar de AL1986
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    434
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 434
    Par défaut
    Je ne m'y connais pas en xml . Mais il me semble que le problème vient des quotes, as tu essayé avec des guillemets pour hoho ou en utilisant des fonctions pour les quotes ?
    En disant d'envoyer le code Delphi, je voulais juste voir comment tu fomulais ta requête (avec des query, execute,...)

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

Discussions similaires

  1. Extraction mysql - Aide
    Par facilitant dans le forum Requêtes
    Réponses: 1
    Dernier message: 04/04/2006, 18h12
  2. [MySQL] aide sur une requete
    Par dj-julio dans le forum Langage SQL
    Réponses: 5
    Dernier message: 12/01/2006, 14h25
  3. aide pour débutant en reseaux
    Par Coolio dans le forum Développement
    Réponses: 1
    Dernier message: 18/12/2005, 00h40
  4. [MySQL] Aide à la création d'une requête
    Par tom06440 dans le forum Requêtes
    Réponses: 6
    Dernier message: 19/10/2005, 22h05
  5. Aide pour débutant : addition
    Par playentry dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 13/03/2005, 19h08

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