MySQL Forums
Forum List  »  Connector/C (libmysql)

Re: Newbie - Connection Issues
Posted by: William Spence
Date: September 18, 2020 01:10PM

Here is stripped down sample code. The code where it breaks is where I implement mysql_real_connect. Unfortunately, it will not connect, and it does not spit out an error message, just a four character grey block?? So I commented out the error block as you can see below and just had it tell me if the connection succeeded or failed. It failed. I feel like it simply does not have access to the mysql code since it cannot even tell me the correct errors. BUT, mysql_init works!! It all runs perfectly from my laptop.



/*
* File: WorkerHalf.c
* Author: bspence
*/

#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
#include <math.h>
#include <string.h>


// FUNCTION Definitions

int deleteRecords(void);
int readDB(void);
int processor(void);
int writeDB(void);
int writeCompsDB(void);


/* ****************************************************************************
* *
* Main Application *
* *
**************************************************************************** */

int main (void) {

MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "[Amazon server address]";
char *user = "[Username]";
char *password = "[Password]";
char *database = "[database name]";
int port = 3306;
int marketCounter = 0;
int z;
conn = mysql_init(NULL);


if (conn == NULL)
{
printf(stderr, "%s\n", mysql_error(conn));
exit(1);
} else {
printf("Conn is good \n");
}

if (mysql_real_connect(conn, server,user,password,database, port, NULL, 0) == NULL)
{
printf("Connection Failure \n");
/*printf(stderr, "%s\n", mysql_error(conn));
mysql_close(conn);
exit(1);*/
} else {
printf("Connection Successful \n");
}

mysql_close(conn);

readDB();
processor();
deleteRecords();
writeDB();
writeCompsDB();

return 1;
}

/* ****************************************************************************
* *
* Deleting Database Records *
* *
**************************************************************************** */

int deleteRecords(void) {
printf("Deleting Records \n");
}

/* ****************************************************************************
* *
* Read all Records into Memory *
* *
**************************************************************************** */

int readDB(void) {

printf("Reading New Records \n");

return 1;
}

/* ****************************************************************************
* *
* Process all the Records *
* *
**************************************************************************** */

int processor(void) {

printf("Processing Records \n");

return 1;
}

/* ****************************************************************************
* *
* Write Records to Database *
* *
**************************************************************************** */

int writeDB(void) {

printf("Writing Records \n");

return 1;
}

/* ****************************************************************************
* *
* Write Comparables to Database *
* *
**************************************************************************** */

int writeCompsDB(void) {

printf("Writing Comps \n");

return 1;
}

Options: ReplyQuote


Subject
Views
Written By
Posted
352
September 18, 2020 11:42AM
107
September 18, 2020 12:10PM
Re: Newbie - Connection Issues
113
September 18, 2020 01:10PM
102
September 18, 2020 03:40PM
97
September 18, 2020 04:33PM
121
September 18, 2020 04:59PM
75
October 12, 2020 03:55PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.