Page 1 of 1

Connect to MySql db

Posted: Sun May 22, 2016 9:20 am
by Marco Turco
Hi all,
I need to connect to a remote mysql db in order to make regular updates.
This is my first experience with mysql. Which is the best way to connect ? I tried the mysql1.prg sample in FWH but it seems the tmysqlserver class doesn't exist.
Do I have to install the mysql odbc ? Thank yoi

Re: Connect to MySql db

Posted: Sun May 22, 2016 12:42 pm
by vilian
Hi Marco,

Use TDolphin from Daniel Garcia, you can found many examples in this fórum. You will need of user and password to connect with the DB. To access a remote DB, Nothing is necessary to install.

Re: Connect to MySql db

Posted: Sun May 22, 2016 5:55 pm
by Marco Turco
Hi,
I Always receive a lot of link errors ? Do I need an updated lib in your opinion ?
FWH Sept 2015 - Embarcadero C++ 7.00

Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN___CLSLOCKDEF' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpsrv
Error: Unresolved external '_hb_gcAllocate' referenced from K:\FWH\LIB\DOLPHIN.LIB|function
Error: Unresolved external '_hb_retclen_buffer' referenced from K:\FWH\LIB\DOLPHIN.LIB|function
Error: Unresolved external '_HB_FUN___CLSUNLOCKDEF' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpsrv
Error: Unresolved external '_HB_FUN_HB_HKEYS' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpsrv
Error: Unresolved external '_HB_FUN___OLEGETACTIVEOBJECT' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpexp
Error: Unresolved external '_HB_FUN___OLECREATEOBJECT' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpexp
Error: Unresolved external '_HB_FUN_HB_HASH' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpqry
Error: Unresolved external '_HB_FUN_HB_HPOS' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpqry
Error: Unresolved external '_HB_FUN_HB_HSET' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpqry
Error: Unresolved external '_HB_FUN_HB_HSETCASEMATCH' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpqry
Error: Unresolved external '_HB_FUN_HB_HCLONE' referenced from K:\FWH\LIB\DOLPHIN.LIB|tdolpqry

Re: Connect to MySql db

Posted: Sun May 22, 2016 10:59 pm
by vilian
Marco,
I think no. I used to use TDolphin with versions oldest than yours.

You need to include LibMySql.lib in your project. This LibMySql.lib you can import from LibMySql.dll

Re: Connect to MySql db

Posted: Mon May 23, 2016 12:17 am
by nageswaragunupudi
You have 3 options.
1) Use TMySql.Lib // harbour contributions
2) Use dolphin.lib // great class from Mr Daniel
3) Use ADO

For options (1) and (2) you need to
(a) Obtain tmysql.lib or dolphin.lib built for xHarbour or Harbour
(b) Download libmysql.dll from mysql site
(c) Make implib libmysql.lib from libmysql.dll
(d) Link your application with tmysql.lib or dolphin.lib and libmysql.lib
(e) Keep libmysql.dll in the exepath.

There are many users in our forum who are using these libs and can help you where to get them from.

Another option is to use ADO. This is very simple and you can get going in 15 minutes.
We can use full features of the server without being restricted by the limitations of the libraries, if any.

Steps:
1) Download MySql ODBC Connector from MySql site. I advice 32 bit msi.
http://dev.mysql.com/downloads/connector/odbc/
2) Install it.
All this you can finish in less than 15 mins and you are ready to go, using FWH ADO functions.

This is a sample program to connect to MySql server on my local PC, open a table and browse. This is tested on FWH 15.09 and works.

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn, oRs

   local cServer     := "localhost"
   local cDataBase   := "fwh"
   local cUser       := "root"
   local cPassWord   := "hidden"

   ? "Start"
   oCn   := FW_OpenAdoConnection( { "MYSQL", cServer, cDataBase, cUser, cPassword }, .t. )
   if oCn == nil
      ? "Connection Fail"
      return nil
   else
      ? "Connected"
   endif

   oRs   := FW_OpenRecordSet( oCn, "customer" )
   XBROWSER oRs
   oRs:Close()
   oCn:Close()

return nil
 
Now, how to use this for your specific need.
You need to know:
a) Your server name. This can be ip address or url provided to you.
b) Database name.
c) User name
d) Password
You may asertain these from the provider.
Use these values in the above program.

First you can check if you successfully connected or not.
If connected, you can open the table you want if you know the table name

Re: Connect to MySql db

Posted: Mon May 30, 2016 3:42 pm
by Marco Turco
Solved with ADO. Thank you.

I only have a problem reading a table with ADO,
I didn't understand how to get data into an array.

For example, doing the following call:
oRs := FW_OpenRecordSet( oCn, "SELECT * FROM company.t_phone;")

How can I get data inside an array ?

Thnak you in advance.

Re: Connect to MySql db

Posted: Mon May 30, 2016 4:27 pm
by nageswaragunupudi
How can I get data inside an array ?

Code: Select all

aData := oRs:GetRows()
oRs:Close()
But may I know why do you want to take the data into an array?

Re: Connect to MySql db

Posted: Sun Nov 13, 2016 9:37 am
by Franklin Demont
nageswaragunupudi wrote:You have 3 options.
1) Use TMySql.Lib // harbour contributions
2) Use dolphin.lib // great class from Mr Daniel
3) Use ADO

For options (1) and (2) you need to
(a) Obtain tmysql.lib or dolphin.lib built for xHarbour or Harbour
(b) Download libmysql.dll from mysql site
(c) Make implib libmysql.lib from libmysql.dll
(d) Link your application with tmysql.lib or dolphin.lib and libmysql.lib
(e) Keep libmysql.dll in the exepath.

There are many users in our forum who are using these libs and can help you where to get them from.

Another option is to use ADO. This is very simple and you can get going in 15 minutes.
We can use full features of the server without being restricted by the limitations of the libraries, if any.

Steps:
1) Download MySql ODBC Connector from MySql site. I advice 32 bit msi.
http://dev.mysql.com/downloads/connector/odbc/
2) Install it.
All this you can finish in less than 15 mins and you are ready to go, using FWH ADO functions.

a) Your server name. This can be ip address or url provided to you.
Hello ,

During a few days i am trying to use MySql :

1) Use TMySql.Lib // harbour contributions
I can't build this lib

2) Use dolphin.lib // great class from Mr Daniel
I can build the ewamples , they are working (made some corrections)
BUT : FWH:ERP2.prg Gives in module login : can't connect (Connect( cHost, cUser, cPassword ))

PLACING THIS COMMAND AT THE BEGINNING (BEFORE DEFINING WINDOW) : NO PROBLEM !!!!!!!!

3) Use ADO :

- downloaded and installed mysql-connector-odbc-5.3.6-win32.msi
- Register a Unicode driver (Windows example)
| shell> myodbc-installer -d -a -n "MySQL ODBC 5.3 Unicode Driver" \
| -t "DRIVER=myodbc5w.dll;SETUP=myodbc5S.dll"
Done , controled with shell> myodbc-installer -d -l , seems ok
- Trying to use ODBC Manager as described in the manuals , but can't add odbc-5.3.6
Only SQL Server appears. Must it be added ?

Trying the example gives , as expected an error DNS name not found

Frank

Re: Connect to MySql db

Posted: Mon Nov 14, 2016 10:17 am
by Franklin Demont
Franklin Demont wrote:
nageswaragunupudi wrote:You have 3 options.

Hello ,

During a few days i am trying to use MySql :

1) Use TMySql.Lib // harbour contributions
I can't build this lib

2) Use dolphin.lib // great class from Mr Daniel
I can build the ewamples , they are working (made some corrections)
BUT : FWH:ERP2.prg Gives in module login : can't connect (Connect( cHost, cUser, cPassword ))

PLACING THIS COMMAND AT THE BEGINNING (BEFORE DEFINING WINDOW) : NO PROBLEM !!!!!!!!

3) Use ADO :

- downloaded and installed mysql-connector-odbc-5.3.6-win32.msi
- Register a Unicode driver (Windows example)
| shell> myodbc-installer -d -a -n "MySQL ODBC 5.3 Unicode Driver" \
| -t "DRIVER=myodbc5w.dll;SETUP=myodbc5S.dll"
Done , controled with shell> myodbc-installer -d -l , seems ok
- Trying to use ODBC Manager as described in the manuals , but can't add odbc-5.3.6
Only SQL Server appears. Must it be added ?

Trying the example gives , as expected an error DNS name not found

Frank
Use ADO Solved :
- downloaded and installed mysql-connector-odbc-5.3.6-win32.msi
- Register a Unicode driver (Windows example)
| shell> myodbc-installer -d -a -n "MySQL ODBC 5.3 Unicode Driver" \
| -t "DRIVER=myodbc5w.dll;SETUP=myodbc5S.dll"
Done , controled with shell> myodbc-installer -d -l , seems ok

THE NAME 'MySQL ODBC 5.3 Unicode Driver' MUST BE USED IN THE CONNECTION STRING

Changed line 37 in Adodfuncs :
{ "MYSQL", "ODBC", { "Driver={MySQL ODBC 5.3 Unicode Driver}", "Driver={MySQL ODBC 3.51 Driver}" }, "Option=3" }, ;


- ODBC Manager : seems not needed

Frank

Re: Connect to MySql db

Posted: Mon Nov 14, 2016 10:42 am
by nageswaragunupudi
May I know what is your FWH version?

if FW_SetUniCode( .t. ) then Fw_OpenAdoConnection(...) automatically uses Unicode driver, without changing the prg.

Code: Select all

FW_SetUnicode( .t. )
oCn := FW_OpenAdoConnection( ... )
FW_SetUnicode( .f. )  // if not required
 

Re: Connect to MySql db

Posted: Mon Nov 14, 2016 11:29 am
by Franklin Demont
nageswaragunupudi wrote:May I know what is your FWH version?

if FW_SetUniCode( .t. ) then Fw_OpenAdoConnection(...) automatically uses Unicode driver, without changing the prg.

Code: Select all

FW_SetUnicode( .t. )
oCn := FW_OpenAdoConnection( ... )
FW_SetUnicode( .f. )  // if not required
 
Sorry , it is only FW1404

Have i to use unicode driver or not ? What is the difference ?
It seems not the be default . Wright ?

I suppose that to change this behaviour i have to use myodbc driver again ? How ?

I noticed that in the list generated with myodbc-installer -d -l also "MySQL ODBC 5.3 ANSI Driver" is present.


Frank

Re: Connect to MySql db

Posted: Mon Nov 14, 2016 12:19 pm
by nageswaragunupudi
My advice does not apply to your version

Because you need not use Unicode in your applications, ANSI driver is best suited to you.

Till I started Unicode development recently, I was working with ANSI driver only. My personal advice to you is to download and install ANSI version only. That works perfectly.

In case you consider upgrading FWH, you can connect to MySql with FWH out of the box, without any need for 3rd party libs. That is also an option.

Re: Connect to MySql db

Posted: Tue Nov 15, 2016 3:03 am
by richard-service
Hi Marco,

I use TMySQL to connect remote access MySQL database.
If you want TMySQL, I can send to you.

Re: Connect to MySql db

Posted: Tue Nov 22, 2016 2:05 am
by devwin2010
Hi Richard

Can you send me Tmysql , source code , and make files to build mysql lib

my email is windev2@yahoo.com.ar

Thanks
Fabian

Re: Connect to MySql db

Posted: Tue Nov 22, 2016 5:34 am
by richard-service
devwin2010 wrote:Hi Richard

Can you send me Tmysql , source code , and make files to build mysql lib

my email is windev2@yahoo.com.ar

Thanks
Fabian
I already sent to you, please check your mail.