Connect to MySql db

Connect to MySql db

Postby Marco Turco » Sun May 22, 2016 9:20 am

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
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Connect to MySql db

Postby vilian » Sun May 22, 2016 12:42 pm

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.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 978
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Connect to MySql db

Postby Marco Turco » Sun May 22, 2016 5:55 pm

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
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Connect to MySql db

Postby vilian » Sun May 22, 2016 10:59 pm

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
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 978
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Connect to MySql db

Postby nageswaragunupudi » Mon May 23, 2016 12:17 am

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  Expand view  RUN

#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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Connect to MySql db

Postby Marco Turco » Mon May 30, 2016 3:42 pm

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.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Connect to MySql db

Postby nageswaragunupudi » Mon May 30, 2016 4:27 pm

How can I get data inside an array ?


Code: Select all  Expand view  RUN
aData := oRs:GetRows()
oRs:Close()


But may I know why do you want to take the data into an array?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Connect to MySql db

Postby Franklin Demont » Sun Nov 13, 2016 9:37 am

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
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Connect to MySql db

Postby Franklin Demont » Mon Nov 14, 2016 10:17 am

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
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Connect to MySql db

Postby nageswaragunupudi » Mon Nov 14, 2016 10:42 am

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  Expand view  RUN
FW_SetUnicode( .t. )
oCn := FW_OpenAdoConnection( ... )
FW_SetUnicode( .f. )  // if not required
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Connect to MySql db

Postby Franklin Demont » Mon Nov 14, 2016 11:29 am

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  Expand view  RUN
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
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Connect to MySql db

Postby nageswaragunupudi » Mon Nov 14, 2016 12:19 pm

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Connect to MySql db

Postby richard-service » Tue Nov 15, 2016 3:03 am

Hi Marco,

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

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 804
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: Connect to MySql db

Postby devwin2010 » Tue Nov 22, 2016 2:05 am

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
devwin2010
 
Posts: 61
Joined: Tue Jul 17, 2007 12:37 pm

Re: Connect to MySql db

Postby richard-service » Tue Nov 22, 2016 5:34 am

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.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 804
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests

cron