This code will compile it in c + +, the idea is to connect to my PC and a remote server, the remote server will receive the records that are captured in my pc and automatically to update the table called "services" in my database "master ". Here is the code done in c + +
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <mysql/mysql.h>
#include <cstring>
#include "config.h"
int main(void)
{
MYSQL mysql;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,loServer,loUser,loPass,loBD,0,NULL,0))
{
printf("NO SE PUEDE CONECTAR AL SERVIDOR LOCAL");
}
const char *query = "SELECT * FROM servicios";
mysql_real_query(&mysql,query,strlen(query));
while (1);
{
//Connect to Main server
MYSQL mysqlmain;
mysql_init(&mysqlmain);
if (!mysql_real_connect(&mysqlmain,remServer,remUser,remPass,remBD,0,NULL,0))
{
printf("NO SE PUEDE CONECTAR AL SERVIDOR REMOTO");
}
char *querymain;
mysql_real_query(&mysqlmain,query,strlen(querymain));
MYSQL_RES *resmain = mysql_store_result(&mysqlmain);
MYSQL_ROW rowmain;
querymain = "INSERT INTO servicios(farmacia,folio,anio,fecha,cuenta,cantidad,codigobarras,caja,sku,ticket,turno,quien) values(";
strcat(querymain,rowmain[0]);
strcat(querymain,",");
strcat(querymain,rowmain[1]);
strcat(querymain,",");
strcat(querymain,rowmain[2]);
strcat(querymain,",");
strcat(querymain,rowmain[3]);
strcat(querymain,",");
strcat(querymain,rowmain[4]);
strcat(querymain,",");
strcat(querymain,rowmain[5]);
strcat(querymain,",");
strcat(querymain,rowmain[6]);
strcat(querymain,",");
strcat(querymain,rowmain[7]);
strcat(querymain,",");
strcat(querymain,rowmain[8]);
strcat(querymain,",");
strcat(querymain,rowmain[9]);
strcat(querymain,",");
strcat(querymain,rowmain[10]);
strcat(querymain,",");
strcat(querymain,rowmain[11]);
strcat(querymain,")");
printf(querymain);
mysql_close(&mysqlmain);
}
mysql_close(&mysql);
sleep(20);
return 0;
exit(EXIT_SUCCESS);
}
-----------------------------------------------------
File "config.h"
const char *loServer = "localhost";
const char *loUser = "root";
const char *loPass = "";
const char *loDB = "master";
const char *remServer = "192.168.0.31"
const char *remUser = "fernando"
const char *remPass = "system"
const char *remDB = "master"
-----------------------------------------------------
The code compiles and runs, but I did not update the table "services", any idea how to correct the code.
|