Get data from mysql and use in a system.
-
Hello..
I have tried to make at little code for my linux machine but it is not so easy.
How the code will work.
- it grab the date from my localhost mysql.
- Run a system commando (echo ‘text’|/home/stats –id testid)
o Where “text” and “testid” is from a table in mysql
- When the system commando is done the “disable” table in mysql shut update from “0” to “1”Her is my mysql table
CREATE TABLE `stats` ( `text` varchar(250) NOT NULL default '', `disabled` int(1) NOT NULL default '0', `id` int(4) NOT NULL auto_increment, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1 ;
I found a code on the internet and I work fine, but it only grab data out..
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; #include "/usr/include/mysql/mysql.h" int main() { /* connection */ MYSQL *handle; /* query result */ MYSQL_RES *result; /* række i query result */ MYSQL_ROW row; /* antal felter i query result */ int nfields; /* pointer til array med felt længder i række i query resuult */ int *l; /* counter */ int i; /* * åben connection til: * server = "localhost" * username = "root" * password = "" * database = "Test" * port = 0 (bliver opfattet som default 3306) */ handle= mysql_init(NULL); if(handle == NULL) { printf("MySQL error: %s", mysql_error(handle)); exit(1); } if(!mysql_real_connect(handle, "localhost", "root", "", "test", 0, NULL, 0)) { printf("MySQL error: %s", mysql_error(handle)); exit(1); } /* udfør query */ mysql_query(handle, "SELECT name FROM test"); result = mysql_store_result(handle); /* print resultat af query */ nfields = mysql_num_fields(result); while ((row = mysql_fetch_row(result))) { l = (int *)mysql_fetch_lengths(result); for (i=0; i<nfields; i++) { printf(" %.*s", row ? l : 4, row ? row : "NULL"); } printf(" "); } /* luk query */ mysql_free_result(result); /* luk connection */ mysql_close(handle); return 0; }
I hope there is one that will make this for me..
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum Datenbanken verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Sorry...i dont know why it ende up ind her !
-
you should specify your problem a bit more in detail, wether it is a c++ problem or a database problem. if you wish a certain work to be done for you, please post at the "Projekte" section and add some information what you are about to pay.