PointOfLight
02-03-2007, 01:06 PM
Since this came up in another thread, I decided to toy with it a bit. To use MySQL in a PPL application (PC only), you must first download the ODBC drivers from MySQL: Home Page. Once you get the drivers installed, do the following in your program:
//put this in the #init function of a form
#include "adodb"
func MySQL_OpenDB(db$, dsn$)
local(con$, strConn$);
con$ = CreateCOMObject("ADODB.Connection");
Invoke(con$, "Open", dsn$);
if (not IsNull(ComError%))
return(false);
end;
db.ConnectString$ = dsn$;
#endif
return(true);
end;
Somewhere else in the program, you might have code like this:
local(connect$, cnt$);
global(db$, rec$);
connect$ = "Driver={mySQL ODBC 3.51 Driver};Server=fileserver;Port=3306;Option=4;Datab ase=rustysab_sabredb;Uid=root;Pwd=MyPassword;";
struct(db$, adodb);
struct(rec$, adorec);
if(MySQL_OpenDB(&db$, connect$))
if(ADO_SelectTable(db$, &rec$, "tblreviews"))
ShowMessage(ADO_FieldCount(rec$));
else
ShowMessage("Unable to open table");
end;
else
ShowMessage("Unable to connect to database");
end;
The key here is the connect string. It is a series of properties separated by ; The properties are as follows:
//should be static except for the driver version (ex: 3.51, 5.0)
Driver={mySQL ODBC 3.51 Driver};
//if on the same box as the app, put localhost here
Server=fileserver;
//only need if server is remote
Port=3306;
//not sure what this does, but I think it needs to
// be different if you want to edit records
Option=4;
//database to connect to
Database=rustysab_sabredb;
//user with sufficent rights to database
Uid=root;
//password for user specified in Uid
Pwd=MyPassword;
I haven't validated that all of the ADO functions work with MySQL, but most of them should. I know that the RecordCount property does not work. Enjoy, and if I get more spare time I might even write up a little something about this.
//put this in the #init function of a form
#include "adodb"
func MySQL_OpenDB(db$, dsn$)
local(con$, strConn$);
con$ = CreateCOMObject("ADODB.Connection");
Invoke(con$, "Open", dsn$);
if (not IsNull(ComError%))
return(false);
end;
db.ConnectString$ = dsn$;
#endif
return(true);
end;
Somewhere else in the program, you might have code like this:
local(connect$, cnt$);
global(db$, rec$);
connect$ = "Driver={mySQL ODBC 3.51 Driver};Server=fileserver;Port=3306;Option=4;Datab ase=rustysab_sabredb;Uid=root;Pwd=MyPassword;";
struct(db$, adodb);
struct(rec$, adorec);
if(MySQL_OpenDB(&db$, connect$))
if(ADO_SelectTable(db$, &rec$, "tblreviews"))
ShowMessage(ADO_FieldCount(rec$));
else
ShowMessage("Unable to open table");
end;
else
ShowMessage("Unable to connect to database");
end;
The key here is the connect string. It is a series of properties separated by ; The properties are as follows:
//should be static except for the driver version (ex: 3.51, 5.0)
Driver={mySQL ODBC 3.51 Driver};
//if on the same box as the app, put localhost here
Server=fileserver;
//only need if server is remote
Port=3306;
//not sure what this does, but I think it needs to
// be different if you want to edit records
Option=4;
//database to connect to
Database=rustysab_sabredb;
//user with sufficent rights to database
Uid=root;
//password for user specified in Uid
Pwd=MyPassword;
I haven't validated that all of the ADO functions work with MySQL, but most of them should. I know that the RecordCount property does not work. Enjoy, and if I get more spare time I might even write up a little something about this.