bast492 | Bonjour, Alors voila pour gérer ma base de donnée mysql j'ai fait un programme en C++ avec l'API de mysql.
C'est un programme qui permeterais d'insérer dans une table une variable. Voila mon problème je n'arive pas a renvoyer un char. Si je veu renvoyer des chiffres le programme marche mais des que la variable est constituer de lettre la valeur dans la table est 0 :
programme (un peu long) : Code :
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <cstring>
- #include <winsock.h>
- #include <mysql.h>
- #define STRING_SIZE 30
- #define INSERT_SAMPLE "INSERT INTO \
- site(nomsite)\
- VALUES(?)"
- ///*,Lien,Priorite*/
- using namespace std;
- int main()
- {
- MYSQL mysql;
- int param_count;
- char str_data [STRING_SIZE];
- unsigned long str_length;
- MYSQL_BIND bind[1];
- my_ulonglong affected_rows;
- my_bool is_null;
- mysql_init(&mysql);
- MYSQL_STMT *stmt;
- stmt = mysql_stmt_init(&mysql);
- mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option" );
- if(mysql_real_connect(&mysql,"localhost","root","admin","bddm",0,NULL,0)){cout<< "all gud"<<endl;}
- //
- if (!stmt)
- {
- fprintf(stderr, " mysql_stmt_init(), out of memory\n" );
- exit(0);
- }
- if (mysql_stmt_prepare(stmt, INSERT_SAMPLE, strlen(INSERT_SAMPLE)))
- {
- fprintf(stderr, " mysql_stmt_prepare(), INSERT failed\n" );
- fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
- exit(0);
- }
- fprintf(stdout, " prepare, INSERT successful\n" );
- // Get the parameter count from the statement
- param_count= mysql_stmt_param_count(stmt);
- fprintf(stdout, " total parameters in INSERT: %d\n", param_count);
- if (param_count != 1) /* validate parameter count */
- {
- fprintf(stderr, " invalid parameter count returned by MySQL\n" );
- exit(0);
- }
- ///* Bind the data for all 4 parameters */
- memset(bind, 0, sizeof(bind));
- ////
- ///* STRING PARAM */
- bind[0].buffer_type=MYSQL_TYPE_STRING;
- bind[0].buffer= (char *)str_data;
- bind[0].buffer_length=STRING_SIZE;
- bind[0].is_null= 0;
- bind[0].length= &str_length;
- ////
- ///*Bind the buffers */
- if (mysql_stmt_bind_param(stmt, bind))
- {
- fprintf(stderr, " mysql_stmt_bind_param() failed\n" );
- fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
- exit(0);
- }
- ///* Specify the data values for the first row */
- const char *aze;
- aze="azeez";
- strncpy(str_data,(char*)aze, STRING_SIZE); /* string */
- str_length= strlen(str_data);
- is_null= 0;
- ///* Execute the INSERT statement - 1*/
- if (mysql_stmt_execute(stmt))
- {
- fprintf(stderr, " mysql_stmt_execute(), 1 failed\n" );
- fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
- exit(0);
- }
- ///* Get the total number of affected rows */
- affected_rows= mysql_stmt_affected_rows(stmt);
- fprintf(stdout, " total affected rows(insert 1): %lu\n",
- (unsigned long) affected_rows);
- if (affected_rows != 1) /* validate affected rows */
- {
- fprintf(stderr, " invalid affected rows by MySQL\n" );
- exit(0);
- }
- ///* Close the statement */
- if (mysql_stmt_close(stmt))
- {
- fprintf(stderr, " failed while closing the statement\n" );
- fprintf(stderr, " %s\n", mysql_stmt_error(stmt));
- exit(0);
- }
- return 0;
- }
|
sa fait 2 jour que je cherche et je trouve pas la solution . help me pls merci d'avance |