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

 C++ Discussion :

Problème avec mysql++


Sujet :

C++

  1. #1
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut Problème avec mysql++
    salut,
    j'ai un problème avec mon code...
    Pour commencer, je suis sous linux ubuntu version 8.04 et j'utilise code blocks

    j'essaie d'apprendre à utiliser mysql++

    voici mon code:
    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
     
    #include <iostream>
    #include <string>
    #include "/usr/include/mysql++/mysql++.h"
     
     
    using namespace std;
     
    int main()
    {
    string serveur,utilisateur;
     
    cout << "Serveur:" << endl;
    getline(cin,serveur);
    cout << "Utilisateur:" << endl;
    getline(cin,utilisateur);
     
    mysqlpp::Connection connect(false);
     
     
    return 0;
    }
    après compilation j'ai les erreurs suivantes:

    erreur: «connection» was not declared in this scope
    erreur: expected `;' before «connect»|
    ||=== Build finished: 2 errors, 0 warnings ===|

    si j'enlève la ligne
    mysqlpp::Connection connect(false);

    tout se passe bien. Comme je le pensais c'est bien cette ligne qui me met ces erreurs...
    Où est l'erreur?

    édit: j'ai trouvé mon erreur il suffisait d'enleser false...
    par contre j'ai encore une erreur en allant plus loin...

    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
     
    string bd_defaut,serveur,utilisateur,mdp;
    const char *p_bd=bd_defaut.c_str(),*p_serveur=serveur.c_str(),*p_utilisateur=utilisateur.c_str(),*p_mdp=mdp.c_str();
     
     
    cout << "Base de données par défaut:" << endl;
    getline(cin,bd_defaut);
    cout << "Serveur:" << endl;
    getline(cin,serveur);
    cout << "Utilisateur:" << endl;
    getline(cin,utilisateur);
    cout << "Mot de passe:" << endl;
    getline(cin,mdp);
     
    mysqlpp::Connection con();
     
    try
    	{
    	con.connect(p_bd,p_serveur,p_utilisateur,p_mdp);
    	cout << "Connection ok" << endl;
    	}
    catch(mysqlpp::Exception e)
    	{
    	cerr << "Erreur de connection" << endl;
    	}
    con.quit();
    return 0;
    }
    voici l'erreur:

    erreur: request for member «connect» in «con», which is of non-class type «mysqlpp::Connection ()()»|
    erreur: request for member «quit» in «con», which is of non-class type «mysqlpp::Connection ()()»|
    ||=== Build finished: 2 errors, 0 warnings ===|

    pourtant j'ai verifié dans le fichier connection.h ces fonction y sont bien...

  2. #2
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 644
    Par défaut
    Salut, et bienvenue sur le forum.

    Autant le dire tout de suite, MySQL++ fait partie de la liste abominable de bibliothèques qu'il me faut encore parcourir, mais...

    Typiquement, les erreurs du type de
    erreur: «quelque chose» was not declared in this scope
    apparaissent dans trois cas principalement:
    1. Soit, tu as "simplement" fait une "faute d'orthographe" dan le nom du type (un "n" de plus ou de moins, un "ct" au lieu d'un "x"...)
    2. Soit tu n'a pas fourni la portée ad-hoc pour accéder au type souhaité.
    3. Soit, enfin, tu n'a pas inclu le fichier d'en-tête dans lequel le type souhaité est effectivement défini

    En l'occurrence, si j'en crois la doc mysqlpp, tu serais dans le troisième cas: il faut inclure le fichier d'en-tête connection.h
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  3. #3
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut
    salut,
    d'après ce que j'ai vu connection.h est un en-tête de mysql++.h donc pour moi c'est bon...
    je vais essayer de regarder mieux le problème de mon coté pour voir...

    je vous tiens au courant

    Edit: je me suis trompé au niveau de la fonction quit... en fait ça c'est en mysql la fonction s'appelle close mais j'ai la même erreur...

    edit2: j'ai fait la manip en ajoutant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     #include <connection.h>
    même erreur...

  4. #4
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 644
    Par défaut
    Ne vas pas croire que je te prenne pour un idiot, car ce n'est pas le cas, mais...

    As-tu fait un copier/coller du code, ou l'a tu réécrit "a mano" dans ton message

    S'il s'agit d'un copier/coller, je devrai donner ma langue au chat.

    Si tu l'a réécrit a mano, vérifie bien l'orthographe (C majuscule, deux n, ction en terminaison)... C'est typiquement le genre d'erreur qui pourrit la vie
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  5. #5
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut
    j'ai jamais dit que tu me prenais pour un idiot peut être je me suis mal exprimé...

    j'ai fais un copier coller de mon code donc de ce coté là pas de soucis...

    j'aurais peut-être dû préciser que j'ai déjà fais de l'assembleur (sauf que c'était des processeurs motorola) un peu de C avec mes profs d'électronique de l'époque (à par déclarer les variables les boucles et les printf scanf c'est tout ce qu'on a vu)...

    Edit: ah oui j'oubliai que j'ai mis à jour ubuntu récemment... on sait jamais si ça peut aider...

    Edit2: le code des fichiers

    mysql++.h

    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
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    /// \file mysql++.h
    /// \brief The main MySQL++ header file.
    ///
    /// This file brings in all MySQL++ headers except for custom.h and
    /// custom-macros.h which are a strictly optional feature of MySQL++.
    ///
    /// There is no point in trying to optimize which headers you include,
    /// because the MySQL++ headers are so intertwined.  You can only get
    /// trivial compile time benefits, at the expense of clarity.
     
    /***********************************************************************
     Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
     MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
     Others may also hold copyrights on code in this file.  See the CREDITS
     file in the top directory of the distribution for details.
     
     This file is part of MySQL++.
     
     MySQL++ is free software; you can redistribute it and/or modify it
     under the terms of the GNU Lesser General Public License as published
     by the Free Software Foundation; either version 2.1 of the License, or
     (at your option) any later version.
     
     MySQL++ is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     License for more details.
     
     You should have received a copy of the GNU Lesser General Public
     License along with MySQL++; if not, write to the Free Software
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
     USA
    ***********************************************************************/
     
    #ifndef MYSQLPP_MYSQLPP_H
    #define MYSQLPP_MYSQLPP_H
     
    /// \brief Encode MySQL++ library version number.
    ///
    /// This macro takes major, minor and bugfix numbers (e.g. 1, 2, and 3)
    /// and encodes them like 0x010203.
    #define MYSQLPP_VERSION(major, minor, bugfix) \
    		(((major) << 16) | ((minor) << 8) | (bugfix))
     
    /// \brief Get the library version number that mysql++.h comes from
    ///
    /// MySQL++ Version number that the mysql++.h header file comes from,
    /// encoded by MYSQLPP_VERSION macro.  Compare this value to what
    /// mysqlpp_lib_version() returns in order to ensure that your program
    /// is using header files from the same version of MySQL++ as the
    /// actual library you're linking to.
    #define MYSQLPP_HEADER_VERSION MYSQLPP_VERSION(2, 3, 2)
     
    // This #include order gives the fewest redundancies in the #include
    // dependency chain.
    #include "connection.h"
    #include "query.h"
    #include "sql_types.h"
     
    namespace mysqlpp {
     
    /// \brief Get the current MySQL++ library version number
    ///
    /// MySQL++ version number that the program is actually linked to,
    /// encoded by MYSQLPP_VERSION macro.  Compare this value to the
    /// MYSQLPP_HEADER_VERSION constant in order to ensure that your
    /// program is using header files from the same version of MySQL++ as
    /// the actual library you're linking to.
    MYSQLPP_EXPORT unsigned int get_library_version();
     
    } // end namespace mysqlpp
     
    #endif // !defined(MYSQLPP_MYSQLPP_H)
     
     
    /**
            \mainpage MySQL++ Reference Manual
     
            \section getting_started Getting Started
     
            The best place to get started is the
            <a href="../userman/index.html">user manual</a>. It provides
            a guide to the example programs and more.
     
     
            \section classes Major Classes
     
            In MySQL++, the main user-facing classes are mysqlpp::Connection,
            mysqlpp::Query, mysqlpp::Result, and mysqlpp::Row.
     
            In addition, MySQL++ has a mechanism called Specialized SQL
            Structures (SSQLS), which allow you to create C++ structures
            that parallel the definition of the tables in your database
            schema. These let you manipulate the data in your database using
            native C++ data structures. Programs using this feature often
            include very little SQL code, because MySQL++ can generate most
            of what you need automatically when using SSQLSes. There is a
            whole chapter in the user manual on how to use this feature of
            the library, plus a section in the user manual's tutorial chapter
            to introduce it. It's possible to use MySQL++ effectively without
            using SSQLS, but it sure makes some things a lot easier.
     
     
            \section files Major Files
     
            The only two header files your program ever needs to include
            are mysql++.h, and optionally custom.h. (The latter implements
            the SSQLS mechanism.) All of the other files are used within
            the library only.
     
     
            \section user_questions If You Have Questions...
     
            If you want to email someone to ask questions about this library,
            we greatly prefer that you send mail to the MySQL++ mailing list,
            which you can subscribe to here: http://lists.mysql.com/plusplus
     
            That mailing list is archived, so if you have questions, do a
            search to see if the question has been asked before.
     
            You may find people's individual email addresses in various
            files within the MySQL++ distribution. Please do not send mail
            to them unless you are sending something that is inherently
            personal. Questions that are about MySQL++ usage may well be
            ignored if you send them to our personal email accounts. Those of
            us still active in MySQL++ development monitor the mailing list,
            so you aren't getting any extra "coverage" by sending messages
            to those addresses in addition to the mailing list.
     
     
            \section licensing Licensing
     
            MySQL++ is licensed under the GNU Lesser General Public License,
            which you should have received with the distribution package in
            a file called "LGPL" or "LICENSE". You can also view it here:
            http://www.gnu.org/licenses/lgpl.html or receive a copy by
            writing to Free Software Foundation, Inc., 51 Franklin Street,
            Fifth Floor, Boston, MA 02110-1301, USA.
    */
    connection.h
    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
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    /// \file connection.h
    /// \brief Declares the Connection class.
    ///
    /// Every program using MySQL++ must create a Connection object, which
    /// manages information about the connection to the MySQL database, and
    /// performs connection-related operations once the connection is up.
    /// Subordinate classes, such as Query and Row take their defaults as
    /// to whether exceptions are thrown when errors are encountered from
    /// the Connection object that created them, directly or indirectly.
     
    /***********************************************************************
     Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
     MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
     Others may also hold copyrights on code in this file.  See the CREDITS
     file in the top directory of the distribution for details.
     
     This file is part of MySQL++.
     
     MySQL++ is free software; you can redistribute it and/or modify it
     under the terms of the GNU Lesser General Public License as published
     by the Free Software Foundation; either version 2.1 of the License, or
     (at your option) any later version.
     
     MySQL++ is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     License for more details.
     
     You should have received a copy of the GNU Lesser General Public
     License along with MySQL++; if not, write to the Free Software
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
     USA
    ***********************************************************************/
     
    #ifndef MYSQLPP_CONNECTION_H
    #define MYSQLPP_CONNECTION_H
     
    #include "common.h"
     
    #include "lockable.h"
    #include "noexceptions.h"
     
    #include <deque>
    #include <string>
     
    namespace mysqlpp {
     
    #if !defined(DOXYGEN_IGNORE)
    // Make Doxygen ignore this
    class MYSQLPP_EXPORT Query;
    #endif
     
    /// \brief Manages the connection to the MySQL database.
     
    class MYSQLPP_EXPORT Connection : public OptionalExceptions, public Lockable
    {
    public:
    	/// \brief Legal types of option arguments
    	enum OptionArgType {
    		opt_type_none,
    		opt_type_string,
    		opt_type_integer,
    		opt_type_boolean
    	};
     
    	/// \brief Per-connection options you can set with set_option()
    	///
    	/// This is currently a combination of the MySQL C API
    	/// \c mysql_option and \c enum_mysql_set_option enums.  It may
    	/// be extended in the future.
    	enum Option 
    	{
    		// Symbolic "first" option, before real options.  Never send
    		// this to set_option()!
    		opt_FIRST = -1,
     
    		opt_connect_timeout = 0,
    		opt_compress,
    		opt_named_pipe,
    		opt_init_command,
    		opt_read_default_file,
    		opt_read_default_group,
    		opt_set_charset_dir,
    		opt_set_charset_name,
    		opt_local_infile,
    		opt_protocol,
    		opt_shared_memory_base_name,
    		opt_read_timeout,
    		opt_write_timeout,
    		opt_use_result,
    		opt_use_remote_connection,
    		opt_use_embedded_connection,
    		opt_guess_connection,
    		opt_set_client_ip,
    		opt_secure_auth,
     
    		// Set multi-query statement support; no argument
    		opt_multi_statements,
     
    		// Set reporting of data truncation errors
    		opt_report_data_truncation,
     
    		// Enable or disable automatic reconnection to the server if
    		// the connection is found to have been lost.
    		opt_reconnect,
     
    		// Number of options supported.  Never send this to
    		// set_option()!
    		opt_COUNT
    	};
     
    	/// \brief Create object without connecting it to the MySQL server.
    	///
    	/// \param te if true, exceptions are thrown on errors
    	Connection(bool te = true);
     
    	/// \brief Create object and connect to database server in one step.
    	///
    	/// This constructor allows you to most fully specify the options
    	/// used when connecting to the MySQL database.  It is the thinnest
    	/// layer in MySQL++ over the MySQL C API function
    	/// \c mysql_real_connect().  The correspondence isn't exact as
    	/// we have some additional parameters you'd have to set with
    	/// \c mysql_option() when using the C API.
    	///
    	/// \param db name of database to use
    	/// \param host host name or IP address of MySQL server, or 0
    	///     if server is running on the same host as your program
    	/// \param user user name to log in under, or 0 to use the user
    	///             name this program is running under
    	/// \param passwd password to use when logging in
    	/// \param port TCP port number MySQL server is listening on, or 0
    	///             to use default value
    	/// \param compress if true, compress data passing through
    	///             connection, to save bandwidth at the expense of CPU time
    	/// \param connect_timeout max seconds to wait for server to
    	///             respond to our connection attempt
    	/// \param socket_name Unix domain socket server is using, if
    	///             connecting to MySQL server on the same host as this program
    	///             running on, or 0 to use default name
    	///     \param client_flag special connection flags. See MySQL C API
    	///             documentation for \c mysql_real_connect() for details.
    	Connection(const char* db, const char* host = "",
    			const char* user = "", const char* passwd = "",
    			uint port = 0, my_bool compress = 0,
    			unsigned int connect_timeout = 60, cchar* socket_name = 0,
    			unsigned int client_flag = 0);
     
    	/// \brief Establish a new connection using the same parameters as
    	/// an existing C API connection.
    	///
    	/// \param other existing Connection object
    	Connection(const Connection& other);
     
    	/// \brief Establish a new connection using the same parameters as
    	/// an existing C API connection.
    	///
    	/// \param mysql existing MySQL C API connection object
    	bool connect(const MYSQL& mysql);
     
    	/// \brief Destroy connection object
    	~Connection();
     
    	/// \brief Connect to database after object is created.
    	///
    	/// It's better to use the connect-on-create constructor if you can.
    	/// See its documentation for the meaning of these parameters.
    	///
    	/// If you call this method on an object that is already connected
    	/// to a database server, the previous connection is dropped and a
    	/// new connection is established.
    	bool connect(cchar* db = "", cchar* host = "",
    			cchar* user = "", cchar* passwd = "", uint port = 0,
    			my_bool compress = 0, unsigned int connect_timeout = 60,
    			cchar* socket_name = 0, unsigned int client_flag = 0);
     
    	/// \brief Close connection to MySQL server.
    	///
    	/// Closes the connection to the MySQL server.
    	void close()
    	{
    		mysql_close(&mysql_);
    		is_connected_ = false;
    	}
     
    	/// \brief Calls MySQL C API function \c mysql_info() and returns
    	/// result as a C++ string.
    	std::string info();
     
    	/// \brief return true if connection was established successfully
    	///
    	/// \return true if connection was established successfully
    	bool connected() const
    	{
    		return is_connected_;
    	}
     
    	/// \brief Return true if the last query was successful
    	bool success() const
    	{
    		return success_;
    	}
     
    	/// \brief Alias for close()
    	void purge() { close(); }
     
    	/// \brief Return a new query object.
    	///
    	/// The returned query object is tied to this MySQL connection,
    	/// so when you call a method like
    	/// \link mysqlpp::Query::execute() execute() \endlink
    	/// on that object, the query is sent to the server this object
    	/// is connected to.
    	Query query();
     
    	/// \brief Alias for success()
    	///
    	/// Alias for success() member function. Allows you to have code
    	/// constructs like this:
    	///
    	/// \code
    	///         Connection conn;
    	///         .... use conn
    	///         if (conn) {
    	///             ... last SQL query was successful
    	///         }
    	///         else {
    	///             ... error occurred in SQL query
    	///         }
    	/// \endcode
    	operator bool() { return success(); }
     
    	/// \brief Copy an existing Connection object's state into this
    	/// object.
    	Connection& operator=(const Connection& rhs);
     
    	/// \brief Return error message for last MySQL error associated with
    	/// this connection.
    	///
    	/// Simply wraps \c mysql_error() in the C API.
    	const char* error()
    	{
    		return mysql_error(&mysql_);
    	}
     
    	/// \brief Return last MySQL error number associated with this
    	/// connection
    	///
    	/// Simply wraps \c mysql_errno() in the C API.
    	int errnum() { return mysql_errno(&mysql_); }
     
    	/// \brief Wraps MySQL C API function \c mysql_refresh()
    	///
    	/// The corresponding C API function is undocumented.  All I know
    	/// is that it's used by \c mysqldump and \c mysqladmin, according
    	/// to MySQL bug database entry http://bugs.mysql.com/bug.php?id=9816
    	/// If that entry changes to say that the function is now documented,
    	/// reevaluate whether we need to wrap it.  It may be that it's not
    	/// supposed to be used by regular end-user programs.
    	int refresh(unsigned int refresh_options)
    	{
    		return mysql_refresh(&mysql_, refresh_options);
    	}
     
    	/// \brief "Pings" the MySQL database
    	///
    	/// Wraps \c mysql_ping() in the C API.  As a result, this function
    	/// will try to reconnect to the server if the connection has been
    	/// dropped.
    	/// 
    	/// \retval 0 if server is responding, regardless of whether we had
    	/// to reconnect or not
    	/// \retval nonzero if either we already know the connection is down
    	/// and cannot re-establish it, or if the server did not respond to
    	/// the ping and we could not re-establish the connection.
    	int ping();
     
    	/// \brief Kill a MySQL server thread
    	///
    	/// \param pid ID of thread to kill
    	///
    	/// Simply wraps \c mysql_kill() in the C API.
    	int kill(unsigned long pid)
    	{
    		return mysql_kill(&mysql_, pid);
    	}
     
    	/// \brief Get MySQL client library version
    	///
    	/// Simply wraps \c mysql_get_client_info() in the C API.
    	std::string client_info()
    	{
    		return std::string(mysql_get_client_info());
    	}
     
    	/// \brief Get information about the network connection
    	///
    	/// String contains info about type of connection and the server
    	/// hostname.
    	///
    	/// Simply wraps \c mysql_get_host_info() in the C API.
    	std::string host_info()
    	{
    		return std::string(mysql_get_host_info(&mysql_));
    	}
     
    	/// \brief Returns version number of MySQL protocol this connection
    	/// is using
    	///
    	/// Simply wraps \c mysql_get_proto_info() in the C API.
    	int proto_info() 
    	{
    		return mysql_get_proto_info(&mysql_);
    	}
     
    	/// \brief Get the MySQL server's version number
    	///
    	/// Simply wraps \c mysql_get_server_info() in the C API.
    	std::string server_info()
    	{
    		return std::string(mysql_get_server_info(&mysql_));
    	}
     
    	/// \brief Returns information about MySQL server status
    	///
    	/// String is similar to that returned by the \c mysqladmin
    	/// \c status command.  Among other things, it contains uptime 
    	/// in seconds, and the number of running threads, questions
    	/// and open tables.
    	std::string stat()
    	{
    		return std::string(mysql_stat(&mysql_));
    	}
     
    	/// \brief Create a database
    	///
    	/// \param db name of database to create
    	///
    	/// \return true if database was created successfully
    	bool create_db(const std::string& db);
     
    	/// \brief Drop a database
    	///
    	/// \param db name of database to destroy
    	///
    	/// \return true if database was created successfully
    	bool drop_db(const std::string& db);
     
    	/// \brief Change to a different database
    	bool select_db(const std::string& db)
    	{
    		return select_db(db.c_str());
    	}
     
    	/// \brief Change to a different database
    	bool select_db(const char* db);
     
    	/// \brief Ask MySQL server to reload the grant tables
    	/// 
    	/// User must have the "reload" privilege.
    	///
    	/// Simply wraps \c mysql_reload() in the C API.  Since that
    	/// function is deprecated, this one is, too.  The MySQL++
    	/// replacement is execute("FLUSH PRIVILEGES").
    	bool reload();
     
    	/// \brief Ask MySQL server to shut down.
    	///
    	/// User must have the "shutdown" privilege.
    	///
    	/// Simply wraps \c mysql_shutdown() in the C API.
    	bool shutdown();
     
    	/// \brief Return the connection options object
    	st_mysql_options get_options() const
    	{
    		return mysql_.options;
    	}
     
    	/// \brief Sets a connection option, with no argument
    	///
    	/// \param option any of the Option enum constants
    	///
    	/// Based on the option you give, this function calls either
    	/// \c mysql_options() or \c mysql_set_server_option() in the C API.
    	///
    	/// There are several overloaded versions of this function.  The
    	/// others take an additional argument for the option and differ
    	/// only by the type of the option.  Unlike with the underlying C
    	/// API, it does matter which of these overloads you call: if you
    	/// use the wrong argument type or pass an argument where one is
    	/// not expected (or vice versa), the call will either throw an
    	/// exception or return false, depending on the object's "throw
    	/// exceptions" flag.
    	///
    	/// This mechanism parallels the underlying C API structure fairly
    	/// closely, but do not expect this to continue in the future.
    	/// Its very purpose is to 'paper over' the differences among the
    	/// C API's option setting mechanisms, so it may become further
    	/// abstracted from these mechanisms.
    	///
    	/// \retval true if option was successfully set, or at least queued
    	/// for setting during connection establishment sequence
    	///
    	/// If exceptions are enabled, a false return means the C API
    	/// rejected the option, or the connection is not established and
    	/// so the option was queued for later processing.  If exceptions
    	/// are disabled, false can also mean that the argument was of the
    	/// wrong type (wrong overload was called), the option value was out
    	/// of range, or the option is not supported by the C API, most
    	/// because it isn't a high enough version. These latter cases will
    	/// cause BadOption exceptions otherwise.
    	bool set_option(Option option);
     
    	/// \brief Sets a connection option, with string argument
    	bool set_option(Option option, const char* arg);
     
    	/// \brief Sets a connection option, with integer argument
    	bool set_option(Option option, unsigned int arg);
     
    	/// \brief Sets a connection option, with Boolean argument
    	bool set_option(Option option, bool arg);
     
    	/// \brief Same as set_option(), except that it won't override
    	/// a previously-set option.
    	bool set_option_default(Option option);
     
    	/// \brief Same as set_option(), except that it won't override
    	/// a previously-set option.
    	template <typename T>
    	bool set_option_default(Option option, T arg);
     
    	/// \brief Returns true if the given option has been set already
    	bool option_set(Option option);
     
    	/// \brief Enable SSL-encrypted connection.
    	///
    	/// \param key the pathname to the key file
    	/// \param cert the pathname to the certificate file
    	/// \param ca the pathname to the certificate authority file
    	/// \param capath directory that contains trusted SSL CA
    	///        certificates in pem format.
        /// \param cipher list of allowable ciphers to use
    	///
    	/// Must be called before connection is established.
    	///
    	/// Wraps \c mysql_ssl_set() in MySQL C API.
    	void enable_ssl(const char* key = 0,
    			const char* cert = 0, const char* ca = 0,
    			const char* capath = 0, const char* cipher = 0);
     
    	/// \brief Return the number of rows affected by the last query
    	///
    	/// Simply wraps \c mysql_affected_rows() in the C API.
    	my_ulonglong affected_rows()
    	{
    		return mysql_affected_rows(&mysql_);
    	}
     
    	/// \brief Get ID generated for an AUTO_INCREMENT column in the
    	/// previous INSERT query.
    	///
    	/// \retval 0 if the previous query did not generate an ID.  Use
    	/// the SQL function LAST_INSERT_ID() if you need the last ID
    	/// generated by any query, not just the previous one.
    	my_ulonglong insert_id()
    	{
    		return mysql_insert_id(&mysql_);
    	}
     
    	/// \brief Insert C API version we're linked against into C++ stream
    	///
    	/// Version will be of the form X.Y.Z, where X is the major version
    	/// number, Y the minor version, and Z the bug fix number.
    	std::ostream& api_version(std::ostream& os);
     
    protected:
    	/// \brief Types of option setting errors we can diagnose
    	enum OptionError {
    		opt_err_type,
    		opt_err_value,
    		opt_err_conn
    	};
     
    	/// \brief Drop the connection to the database server
    	///
    	/// This method is protected because it should only be used within
    	/// the library.  Unless you use the default constructor, this
    	/// object should always be connected.
    	void disconnect();
     
    	/// \brief Error handling routine for set_option()
    	bool bad_option(Option option, OptionError error);
     
    	/// \brief Given option value, return its proper argument type
    	OptionArgType option_arg_type(Option option);
     
    	/// \brief Set MySQL C API connection option
    	///
    	/// Wraps \c mysql_options() in C API.  This is an internal
    	/// implementation detail, to be used only by the public overloads
    	/// above.
    	bool set_option_impl(mysql_option moption, const void* arg = 0);
     
    #if MYSQL_VERSION_ID >= 40101
    	/// \brief Set MySQL C API connection option
    	///
    	/// Wraps \c mysql_set_server_option() in C API.  This is an
    	/// internal implementation detail, to be used only by the public
    	/// overloads above.
    	bool set_option_impl(enum_mysql_set_option msoption);
    #endif
     
    	/// \brief Establish a new connection as a copy of an existing one
    	///
    	/// \param other the connection to copy
    	void copy(const Connection& other);
     
    private:
    	friend class ResNSel;
    	friend class ResUse;
    	friend class Query;
     
    	struct OptionInfo {
    		Option option;
    		OptionArgType arg_type;
    		std::string str_arg;
    		unsigned int int_arg;
    		bool bool_arg;
     
    		OptionInfo(Option o) :
    		option(o),
    		arg_type(opt_type_none),
    		int_arg(0),
    		bool_arg(false)
    		{
    		}
     
    		OptionInfo(Option o, const char* a) :
    		option(o),
    		arg_type(opt_type_string),
    		str_arg(a),
    		int_arg(0),
    		bool_arg(false)
    		{
    		}
     
    		OptionInfo(Option o, unsigned int a) :
    		option(o),
    		arg_type(opt_type_integer),
    		int_arg(a),
    		bool_arg(false)
    		{
    		}
     
    		OptionInfo(Option o, bool a) :
    		option(o),
    		arg_type(opt_type_boolean),
    		int_arg(0),
    		bool_arg(a)
    		{
    		}
    	};
    	typedef std::deque<OptionInfo> OptionList;
    	typedef OptionList::const_iterator OptionListIt;
     
    	MYSQL mysql_;
    	bool is_connected_;
    	bool connecting_;
    	bool success_;
    	OptionList applied_options_;
    	static OptionArgType legal_opt_arg_types_[];
    };
     
     
    } // end namespace mysqlpp
     
    #endif

  6. #6
    Expert éminent
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 644
    Par défaut
    A vrai dire, j'avais conscience en écrivant le message précédent qu'il risquait d'être très mal interprété, et c'est la raison pour laquelle j'ai précisé directement qu'il ne fallait pas se sentir agressé
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  7. #7
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut
    t'inquiète y a aucun soucis

    sinon pour revenir à mon problème j'ai cherché mais j'ai toujours pas trouver...

  8. #8
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    Salut et bienvenu sur le Forum,
    En préambule, n'hésite jamais à faire un petit tour côte FAQ et tutoriels. Ce sont des ressources aussi précieuses que le forum. Car... en l'occurrence, il te faut remplacer mysqlpp::Connection con(); par mysqlpp::Connection con; comme justement indiqué dans cette entrée de la FAQ.
    Cordialement.

    Autre chose me chagrine:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    const char *p_bd=bd_defaut.c_str(),*p_serveur=serveur.c_str(),*p_utilisateur=utilisateur.c_str(),*p_mdp=mdp.c_str();
    Cf ici.

    J'aurais fait quelque chose comme ça:
    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
     
    string bd_defaut,serveur,utilisateur,mdp;
     
     
    cout << "Base de données par défaut:" << endl;
    cin>>bd_defaut;
    cout << "Serveur:" << endl;
    cin>>serveur;
    cout << "Utilisateur:" << endl;
    cin>>utilisateur;
    cout << "Mot de passe:" << endl;
    cin>>mdp;
     
    ....
    con.connect(bd_defaut.c_str(),serveur.c_str(),utilisateur.c_str(),mdp.c_str());

  9. #9
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut
    j'ai remplacé mysqlpp::Connection con(); par mysqlpp::Connection con; même si je l'avais déjà fais...
    voici les erreurs dans ce cas:


    ||=== mysql, Debug ===|
    In function `main'
    23|undefined reference to `mysqlpp::Connection::Connection(bool)'|
    27|undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int, char, unsigned int, char const*, unsigned int)'|
    37|undefined reference to `mysqlpp::Connection::~Connection()'|
    37|undefined reference to `mysqlpp::Connection::~Connection()'|
    In function `mysqlpp::Connection::close()'
    182|undefined reference to `mysql_close'|
    ||=== Build finished: 5 errors, 0 warnings ===|


    vu les problèmes je pense que je vais passer par la bibliothèque mysql en C et créer mes classes avec ça (ça a l'air bien mieux documenté..)

    merci quand même pour votre aide

  10. #10
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    Bonjour,
    Cela ressemble à des erreurs de link et laisse penser que tu n'as pas inclus la bibliothèque adéquate dans les paramètres de linkage.

  11. #11
    Membre très actif
    Homme Profil pro
    technicien en électronique
    Inscrit en
    Octobre 2008
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : technicien en électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 74
    Par défaut
    j'ai réessayé de trouver le problème et en effet j'avais pas lié les .a alors que les .h y était
    c'est la première fois que je fais un programme sans les bibliothèques standards...
    bon au moins j'aurais appris quelque chose et en plus ça marche avec quelques modifications...
    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
    using namespace std;
     
    int main()
    {
    string bd_defaut,serveur,utilisateur,mdp;
     
    do
    	{
    	cout << "Base de données par défaut:" << endl;
    	getline(cin,bd_defaut);
    	cout << "Serveur:" << endl;
    	getline(cin,serveur);
    	cout << "Utilisateur:" << endl;
    	getline(cin,utilisateur);
    	cout << "Mot de passe:" << endl;
    	getline(cin,mdp);
    	}
    while(utilisateur=="");
     
    try
    	{
    	mysqlpp::Connection session(bd_defaut.c_str(),serveur.c_str(),utilisateur.c_str(),mdp.c_str());
    	session.close();
    	}
    catch(mysqlpp::BadQuery e)
    	{
    	cerr << "Erreur" << e.what() << endl;
        return 1;
    	}
    catch (mysqlpp::Exception e)
    	{
        cerr << "Erreur générale : " << e.what() << endl;
        return 1;
    	}
     
    return 0;
    }
    merci quand même
    maintenant je vais essayer de le compliquer un peu...

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

Discussions similaires

  1. Problème avec mysql.host
    Par LePhasme dans le forum Installation
    Réponses: 4
    Dernier message: 05/03/2012, 10h23
  2. problème avec MYSQL
    Par H-bil dans le forum Requêtes
    Réponses: 1
    Dernier message: 25/06/2006, 22h21
  3. Problème Avec MySQL, PHP5 et IIS6
    Par nemesix29 dans le forum Apache
    Réponses: 3
    Dernier message: 30/04/2006, 19h37
  4. Problème avec MySQL.Data
    Par MABB dans le forum Delphi .NET
    Réponses: 1
    Dernier message: 08/04/2006, 18h41
  5. problème avec MySql
    Par cescu dans le forum Requêtes
    Réponses: 4
    Dernier message: 20/02/2006, 12h18

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