Question: Why do I fail making a database and tables? #define _ CRT _ SECURE _ NO _ WARNINGS #include #include #include mysql . h
Why do I fail making a database and tables?
#define CRTSECURENOWARNINGS
#include
#include
#include mysqlh
#pragma commentlib "libmysql.lib"
const char host "localhost"; change if necessary
const char user "root"; change if necessary
const char pw "dltjgus; change if necessary
const char db "project;
#define MAXLEN
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryTypeMYSQL conn;
void queryResultMYSQL conn, const char query
if mysqlqueryconn query
printfQuery failed: s
mysqlerrorconn;
return;
MYSQLRES result mysqlstoreresultconn;
if result NULL
printfFailed to retrieve result set: s
mysqlerrorconn;
return;
int numfields mysqlnumfieldsresult;
MYSQLROW row;
while row mysqlfetchrowresult
for int i ; i numfields; i
if rowi NULL
printfs rowi;
else
printfNULL ;
printf
;
mysqlfreeresultresult;
int mainvoid
MYSQL connection NULL;
MYSQL conn;
MYSQLRES sqlresult;
MYSQLROW sqlrow;
FILE fp fopenCRUDtxtrt;; open CRUD file.
char lineMAXLEN;
int state ;
int enter;
if fp NULL
fprintfstderr "open file error!";
exit;
if mysqlinit&conn NULL
printfmysqlinit error!";
return ;
connection mysqlrealconnect&conn, host, user, pw dbconst charNULL;
if connection NULL
printfd ERROR : s
mysqlerrno&conn mysqlerror&conn;
return ;
else
printfConnection Succeeded
;
while fgetsline sizeofline fp NULL
if strcmpline$$$
read lines from CRUD file, $$$ separates CREATE DELETE parts.
break;
mysqlqueryconnection line;
if mysqlselectdb&conn, "project
printfd ERROR : s
mysqlerrno&conn mysqlerror&conn;
return ;
const char query "SELECT FROM customer";
state mysqlqueryconnection query;
if state
sqlresult mysqlstoreresultconnection;
printf SELECT FROM CUSTOMER
;
while sqlrow mysqlfetchrowsqlresult NULL
printfs s s s
sqlrow sqlrow sqlrow sqlrow;
mysqlfreeresultsqlresult;
comment out if you want to persist example db instance.
while fgetsline sizeofline fp NULL
mysqlqueryconnection line; these are DELETEs & DROPs.
fclosefp;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
