MySQL-C++ - Connector immer ein string mit der SELECT-Abfrage

Ich bin neu in mysql an c++, habe es vor zu VERPFÄNDEN, hat Super geklappt, aber jetzt habe ich ein problem. Ich versuche, ein Passwort aus der mysql-Datenbank, werden Sie den rest des Codes später und ich bin immer ein hex-code? wenn das richtig? Hier ist ein Beispiel was ich immer bin: 0x59fcb0. Es ist immer ändert, wenn ich das Programm neu starten/kompilieren. Ich habe versucht, google für mein problem, aber nicht bekommen, alles in der Nähe. Also das einzige, was ich tun möchte, Ist, um einen Wert in ein Feld und speichern Sie es als eine variable... Hier ist mein code:

#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <iostream>
#include <string>

#include <windows.h>
#include <mysql/mysql.h>

using namespace std;

static char *opt_host_name = "host"; /* HOST */
static char *opt_user_name = "user"; /* USERNAME */
static char *opt_password = "pass"; /* PASSWORD */
static unsigned int opt_port_num = 3306; /* PORT */
static char *opt_socket_name = NULL; /* SOCKET NAME, DO NOT CHANGE */
static char *opt_db_name = "database name"; /* DATABASE NAME */
static unsigned int opt_flags = 0; /* CONNECTION FLAGS, DO NOT CHANGE */

int main ()
{
    MYSQL *conn; /* pointer to connection handler */
    MYSQL_RES *res; /* holds the result set */
    MYSQL_ROW row;

    /* INITIALIZE CONNECTION HANDLER, DO NOT CHANGE */
    conn = mysql_init (NULL);

    /* THIS CONNECTS TO SERVER, DO NOT CHANGE ANYTHING HERE */
    mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password,
    opt_db_name, opt_port_num, opt_socket_name, opt_flags);
    /* show tables in the database (test for errors also) */
    mysql_query(conn, "SELECT Password FROM Users WHERE Name = 'MY_NICKNAME'");
    res = mysql_store_result(conn);
    cout << "Password is: \n";
    cout << res << endl;

    /* disconnect from server */
    mysql_close (conn);

    system("pause");
    return 0;
} 
/* end main function */

Außerdem habe ich geändert, die mysql-Datenbank-Optionen.

  • Wie es aussieht bist du mit dem MySQL-C-API, nicht die C++ - Connector.
  • Müssen Sie rufen Sie eine der mysql_fetch_XXX Funktionen zum abrufen der Zeile aus dem Ergebnis.
InformationsquelleAutor KlaudijusM | 2013-08-24
Schreibe einen Kommentar