[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Help compiling a file with c++ in CentOS

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Help compiling a file with c++ in CentOS

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by LicFerSH   (1 post)  [Biography] bio
Date Thu 14 Jun 2012 09:48 PM (UTC)  quote  ]
Message
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.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


570 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]