How can I read data from MySQL 5 database?

1C:Enterprise platform integration capabilities and techniques

#1
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company:

I need to read and maybe write data from/to a database in MySQL 5 DBMS. Is it possible? And how can I do that?

 
#2
People who like this:1Yes/0No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

Yes, its possible. At first you need driver, and then

Code
ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;Port=3306;
|DATABASE=someDatabase;UID=user;PASSWORD=pass;
|OPTION=3;STMT=SET CHARACTER SET cp1251";
Connection     = New COMObject("ADODB.Connection");
Connection.Open(ConnectionString);

Command = New COMObject("ADODB.Command");
Command.ActiveConnection = Connection;
Command.CommandText = "select id fr om table";
Command.CommandType = 1;
       
RecordSet = New COMObject("ADODB.RecordSet");
RecordSet = Command.Execute();
While Not RecordSet.EOF Do
     Message(RecordSet.Fields("id").Value);
     RecordSet.MoveNext();
EndDo;

Edited: ivan avdonin - Dec 14, 2012 10:30 AM
 
#3
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company:

I received the following error:

{ManagedApplicationModule(7)}: Error calling context method (Open)
Connection.Open(ConnectionString);
because:
An exception has occurred (Microsoft OLE DB Provider for ODBC Drivers): [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

 
#4
People who like this:1Yes/0No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

check driver for proper installation
I use mysql-connector-odbc-5.2.2-win32.msi from mysql odbc driver

im not sure, but maybe win64 will approach too

and also remove text wrapping in connection string, I do it for nice view at forum

Edited: ivan avdonin - Dec 14, 2012 12:03 PM
 
#5
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company:

It works!
I have downloaded and installed Connector/ODBC 5.2.2 Windows (x86, 32-bit), MSI Installer Connector-ODBC and changed the driver name to MySQL ODBC 5.2w Driver. By the way, the 64-bit version did not appeared in MS Excel when I tried to create a new data source to get a list of available ODBC connectors.
Thanks to Ivan!

P.S.:
It works fine even without of this line:

Code
RecordSet = New COMObject("ADODB.RecordSet");

Edited: Xin Wang - Dec 14, 2012 01:05 PM
 
Subscribe
Be the first to know tips & trick on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.