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
|
#include <iostream> // input/output streams.
#include <mysql.h> // the mysql header
using namespace std; // omg, std namespace
// jeez, shortest header i've ever had.
MYSQL *connection, mysql; // variables
MYSQL_RES *result; // more variables
MYSQL_ROW row; // even more
int query_state; // and even more
class BBQSQL { // zomfg its a class!
public: // public
void connect(); // here's where we define the connect function!
void disconnect(); // here's where we define the disconnect function!
private: // private
int disconnected; // here's a useless variable that i put because i was unsure about classes requiring private
};
void BBQSQL::connect() { // the mysql connect function
mysql_init(&mysql); // dunno what this does. it initiates mysql i believe.
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,/*Host*/,/*Username*/,/*Password*/,"bogusnews",0,0,0);
if (connection == NULL) { // if the connection fails
cout << mysql_error(&mysql) << endl; // give us an error
}
}
void BBQSQL::disconnect() { // the mysql disconnect function
mysql_free_result(result); // clearing results, i think
mysql_close(connection); // dropping the connection
disconnected = 1; // working with that useless variable
}
int main() { // The main function
BBQSQL BoGUS; // defining BoGUS as a mysql class :)
BoGUS.connect(); // connecting...!
query_state = mysql_query(connection, "SELECT MAX(ID) FROM bogusnews"); // omg im querying for the highest ID.
if (query_state !=0) { // if the query state has an error...
cout << mysql_error(connection) << endl; // show us what happened.
} // why am i commenting this? its just the end of an if statement
result = mysql_store_result(connection); // results!
while ( ( row = mysql_fetch_row(result)) != NULL ) { // OMG! lets see if the results are working
cout << row[1] << endl; // this is where we show the results.
} // why am i commenting on this? its just the end of a while statement
BoGUS.disconnect(); // disconnecting!!!!!1
} // the end of the main function :O
|