tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
3294
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Avatar von FBIagent
    FBIagent FBIagent ist offline Mitglied Brokat
    Registriert seit
    Jan 2005
    Beiträge
    281
    Moin,

    wie im Betreff gesagt connecte ich zu meinem MySQL Server(localhost).
    Für die MySQL connection habe ich mir eine ganz kleine Klasse geschrieben.

    Wenn die connection beendet wird und wieder aufgebaut werden soll funktioniert es
    nicht mehr. Wäre nett wenn mir jemand helfen könnte den Fehler zu finden ich sehe da überhaupt nichts falsches.

    Hier etwas 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
    
    //// mysqlConnection.h ////
    #ifndef MYSQLCONNECTION_H
    #define MYSQLCONNECTION_H
     
    #include <iostream>
    #include <windows.h>
    #include <MySQL\mysql.h>
     
    class mysqlConnection
    {
    private:
      MYSQL conn;
      std::string info[4];
    public:
      void setInfo(std::string host,std::string user,std::string password, std::string database);
      bool connect();
      bool query(std::string data);
      MYSQL_RES *lastRes();
      void resFree(MYSQL_RES *data);
      void close();
    };
    #endif
     
    //// mysqlConnection.cpp ////
    #include "mysqlConnection.h"
     
    void mysqlConnection::setInfo(std::string host,std::string user,std::string password,std::string database)
    {
      info[0] = host;
      info[1] = user;
      info[2] = password;
      info[3] = database;
    }
     
    bool mysqlConnection::connect()
    {
      mysql_init(&conn);
     
      if(mysql_real_connect(&conn,info[0].c_str(),info[1].c_str(),info[2].c_str(),info[3].c_str(),3306,NULL,0))
        return true;
      else
        return false;
    }
     
    bool mysqlConnection::query(std::string data)
    {
      if(!mysql_query(&conn,data.c_str()))
        return false;
      else
        return true;
    }
     
    MYSQL_RES *mysqlConnection::lastRes()
    {
      return mysql_store_result(&conn);
    }
     
    void mysqlConnection::resFree(MYSQL_RES *data)
    {
      mysql_free_result(data);
    }
     
    void mysqlConnection::close()
    {
      mysql_close(&conn);
    }
     
    Don't blame people for bugs. Work together to make things better. No
    finger pointing! Not ever! A good rule is to Never Assume An Attack.
    If you find yourself getting angry, assume it's a misunderstanding, not an
    attack.

  2. #2
    bk75 bk75 ist offline Mitglied Silber
    Registriert seit
    Mar 2006
    Ort
    Internet
    Beiträge
    74
    Du solltest vielleicht mal zeigen wie Du Deine Klasse benutzt und wie Du den Reconnect machst.
     
    X-ITEC IT-Consulting
    X-ITEC CMS * Win / Linux Programmierung * 2D / 3D Coding * C/C++ * PHP * Assembler * Security-Research

Ähnliche Themen

  1. MySQL Connection
    Von crsakawolf im Forum ASP
    Antworten: 4
    Letzter Beitrag: 05.01.10, 08:19
  2. Problem mit MySQL extern Connection s4y
    Von Moba im Forum Relationale Datenbanksysteme
    Antworten: 1
    Letzter Beitrag: 27.02.07, 00:01
  3. Mysql connection
    Von cavigelli im Forum Relationale Datenbanksysteme
    Antworten: 2
    Letzter Beitrag: 05.07.06, 16:53
  4. mysql connection mit c++
    Von the_smooth im Forum C/C++
    Antworten: 4
    Letzter Beitrag: 30.11.04, 18:17
  5. mySQL connection
    Von dji im Forum ASP
    Antworten: 5
    Letzter Beitrag: 30.08.02, 10:17