1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
// EsKueEl.h
#include <iostream> // input/output stream
#include <mysql.h> // so the ksql class can use mysql o.o
#include <string> // so we can use strings
using namespace std; // the standard namespace o.o
class qksql { // QKSQL : Quick MySQL
public: // the public functions and variables
void connect(char host[1000], char usr[1000], char pass[1000], char db[1000]); // the connect function...
void disconnect(); // time to go bye bye!
int query(char myquery[10000]); // query my query pl0x
char query_result(); // a char-returning function... O.o
int query_state; // the query_state o.o yeah, its public.
MYSQL *connection, mysql; // mysql stuff...
MYSQL_RES *result; // mysql stuff....
MYSQL_ROW row; // mysql stuff...
void max_res(int x); // use this function to set the max results, this is good for a simple querying program
private: // getting to the private variables!
int i; // the count up int :O
int t; // the function'd row
}; // the end... :O
void qksql::connect(char host[1000], char usr[1000], char pass[1000], char db[1000]) { // connection with defined variables
mysql_init(&mysql); // initiating mysql :O
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,host,usr,pass,db,0,0,0);
if (connection == NULL) { // if the connection fails
cout << mysql_error(&mysql) << endl; // give us an error
}
}
void qksql::disconnect() { // disconnectz0r
mysql_free_result(result); // freeing query results
mysql_close(connection); // dropping the connection
}
int qksql::query(char myquery[10000]) { // query teh stringz
query_state = mysql_query(connection, myquery); // querying!
if (query_state != 0) { // if the query state has an error...
cout << mysql_error(connection) << endl; // show us what happened.
return 1; // returning with error code 1 :O
}
}
char qksql::query_result() {
result = mysql_store_result(connection); // results!
while ( ( row = mysql_fetch_row(result)) != NULL ) { // OMG! lets see if the results are working
fast: // heh... yes, ik, ik... goto is very bad...
if (i < t) { // if i < t
cout << row[i] << endl;; // output row[i]
++i; // add 1 to i
goto fast; // go to fast :O
} // O.o why was this a char again?
} // seriously, it has no return value
} // whatever... i forget :D
void qksql::max_res(int x) { // the max res function
t = x; // private T is now equal to incoming X
} // bye bye!
| |