Connecting to a MySql database

 
Hi there. Hoping for some assistance with an EA and connecting to a mysql db.

I'm connecting at present using the libmysql.dll and some code found on MT4 forums (see below). What I'm having a nightmare with is returning and viewing the result set from a simple select query. I can update the mysql db via insert and append queries without any problems. The code I've found is as below. If anyone can help with an example of returning results from a simple select query I'd be most grateful. Obviously this is possible, I just can't get my head around the declarations in the dll needed to get it to work.

Many thanks.

#import "libmysql.dll"
int mysql_init(int db);
int mysql_errno(int TMYSQL);
int mysql_real_connect(int TMYSQL, string host, string user, string password, 
                       string DB,int port,int socket,int clientflag);
int mysql_real_query(int TMSQL, string query, int length);
void mysql_close(int TMSQL);
#import

int mysql;

int start()
  {

   mysql = mysql_init(mysql);
   if(mysql != 0) 
       Print("allocated ", mysql);
   string host = "localhost";
   string user = "testuser";
   string password = "password";
   string DB = "test";
   int clientflag = 0;
   int port = 3306;
   string socket = "";
   int res = mysql_real_connect(mysql,host,user,password,DB,port,socket,clientflag);
   int err = GetLastError();
   if(res == mysql) 
       Print("connected");
   else 
       Print("error=", mysql, " ", mysql_errno(mysql), " ");

   string query = "";
   int length = 0;
   query = "select * from MyTable";
   length = StringLen(query);
   mysql_real_query(mysql, query, length);

   int myerr = mysql_errno(mysql);
   if(myerr > 0)
       Print("error=",myerr);

   mysql_close(mysql);

   return(0);
  }
 
Take a look at http://dev.mysql.com/tech-resources/articles/embedding-mysql-server.html

But I don't think EA's allow pointers like MYSQL *mysql;

Maybe you can put the pointer code in the dll, and the while loop in the sample script (at the bottom) in the EA code?
 
 // php sample

 $sql = "SELECT time, ... "; 
 $res = mysql_query($sql, $link);
 
 while ($row = mysql_fetch_assoc($res))
 {
    echo $row["time"];
 }
  
  mysql_free_result($res);