BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to connect to mysql server

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Renan
Guest





PostPosted: Mon Nov 06, 2006 6:40 pm    Post subject: How to connect to mysql server Reply with quote



Now, I don't know almost anything about database (I know a little about paradox using bde). I need to know how do I connect to a MySQL server, local and remote. Local is just for testing, and remote is for people here at work to use.

Thanks

Renan BS
Back to top
Antaeus
Guest





PostPosted: Tue Nov 07, 2006 9:10 am    Post subject: Re: How to connect to mysql server Reply with quote



Hello.

You can try to use Core Lab's Data Access Components for MySQL server
(MyDAC). More detailed information about MyDAC is available on the following
page: http://crlab.com/mydac/.

Best regards,
Antaeus, Core Lab Team.

"Renan" <nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com> wrote in message
news:454f3b42$1 (AT) newsgroups (DOT) borland.com...
Quote:

Now, I don't know almost anything about database (I know a little about
paradox using bde). I need to know how do I connect to a MySQL server, local

and remote. Local is just for testing, and remote is for people here at work
to use.
Quote:

Thanks

Renan BS
Back to top
kw
Guest





PostPosted: Tue Nov 07, 2006 9:10 am    Post subject: Re: How to connect to mysql server Reply with quote



"Renan" <nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com> 撰寫於郵件新聞:454f3b42$1 (AT) newsgroups (DOT) borland.com...
Quote:

Now, I don't know almost anything about database (I know a little about
paradox using bde). I need to know how do I connect to a MySQL server,
local and remote. Local is just for testing, and remote is for people here
at work to use.


by using DBExpress components included in C++Builder6 (PRO) or C++Builder
for BDS2006 or TC++ Explorer. Be warned though that the DBExpress components
are buggy and as far as I know, _DO_NOT_ support MySQL version 4.1.7 or
higher. DBExpress included in TC++ Explorer (which is actually a free
edition of C++Builder for BDS2006) is not even working with MySQL versions
prior to 4.1.7 (For the one used in AppServ 5.2.1, at least), I'm still
having problem getting them to work.

To connect to a MySQL server, drop a TSQLConnection component (in the
DBExpress palatte page) to your form, chose the ConnectionName as
MySQLConnection, DriverName as MySQL and set the Params according to this:

-if you are connecting to your local computer:
HostName - localhost (or 127.0.0.1 or your local computer name)
-or if you are connecting to a remote computer:
HostName - (your remote server's domain name)

-These will be same regardless of local or remote connection:
Database - (the database name you want to connect to)
User_Name - (your database user name, or log in name)
Password - (the password to access your database)

You can leave the rest at default unless you have other requirements.


Quote:
Thanks

Renan BS
Back to top
Renan
Guest





PostPosted: Tue Nov 07, 2006 10:52 pm    Post subject: Re: How to connect to mysql server Reply with quote

"kw" <kw (AT) nospam (DOT) com> wrote:
Quote:

"Renan" <nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com> 撰寫於郵件新聞:454f3b42$1 (AT) newsgroups (DOT) borland.com...

Now, I don't know almost anything about database (I know a little about
paradox using bde). I need to know how do I connect to a MySQL server,
local and remote. Local is just for testing, and remote is for people here
at work to use.


by using DBExpress components included in C++Builder6 (PRO) or C++Builder
for BDS2006 or TC++ Explorer. Be warned though that the DBExpress components
are buggy and as far as I know, _DO_NOT_ support MySQL version 4.1.7 or
higher. DBExpress included in TC++ Explorer (which is actually a free
edition of C++Builder for BDS2006) is not even working with MySQL versions
prior to 4.1.7 (For the one used in AppServ 5.2.1, at least), I'm still
having problem getting them to work.

To connect to a MySQL server, drop a TSQLConnection component (in the
DBExpress palatte page) to your form, chose the ConnectionName as
MySQLConnection, DriverName as MySQL and set the Params according to this:

-if you are connecting to your local computer:
HostName - localhost (or 127.0.0.1 or your local computer name)
-or if you are connecting to a remote computer:
HostName - (your remote server's domain name)

-These will be same regardless of local or remote connection:
Database - (the database name you want to connect to)
User_Name - (your database user name, or log in name)
Password - (the password to access your database)

You can leave the rest at default unless you have other requirements.


Thanks

Renan BS

I found an example about how to use this components. But it complains about: "Unable to load libmysql.dll". It 's something like this. I have MySQL installed on my PC, and I put libmysql.dll in system, system32 and in the directory that the executable is created, and I still get this error. What is it??

Renan BS
Back to top
kw
Guest





PostPosted: Wed Nov 08, 2006 9:10 am    Post subject: Re: How to connect to mysql server Reply with quote

"Renan" <nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com> 撰寫於郵件新聞:4550c7cb$1 (AT) newsgroups (DOT) borland.com...
Quote:
I found an example about how to use this components. But it complains
about: "Unable to load libmysql.dll". It 's something like this. I have
MySQL installed on my PC, and I put libmysql.dll in system, system32 and
in the directory that the executable is created, and I still get this
error. What is it??


I roughly recalled about I was having the same problem back then, but can't
really pinpoint where it arise - I was experimenting with countless
configuration and settings before I finally get dbExpress to work with
MySQL, so much trials untill my memory is all mixed up....

Here are somethings I could think of: (answers based on C++Builder6)
1) when configuring the TSQLConnection, make sure you choose the
ConnectionName instead of DriverName - the DriverName will change to MySQL
automatically if you select MySQLConnection from ConnectionName. It will
cause some problem if you do it the other way round, as far as I can
remember.

2) make sure your MySQL is not of version 4.1.x or newer. You might want to
get version 4.0.20 (which is what I'm using, along with C++Builder6), just
don't use 4.1.x or newer. I would recommend you download and install AppServ
2.5.1, which includes Apache server, PHP5, MySQL 4.0.20, and phpMyAdmin, all
configured to work fine together, as long as you are using the dbExpress
from C++Builder6. phpMyAdmin is a nice browser based GUI MySQL managing
tool.

most likely the "Unable to load libmysql.dll" problem is due to the MySQL
you are using is version 5.x, I guess. If that's the case, uninstall MySQL
5.x and search for all the libmysql.dll and delete them, then install MySQL
4.0.x (or AppServ 2.5.1, if you want a fully integrated web server and a
nice GUI tool for MySQL database management)(note: the web server is just
for use with phpMyAdmin, it has nothing to do with the MySQL server in the
package, so you can disable it after you installed AppServ, if you are not
going to use phpMyAdmin).

If you must use MySQL 5.x, then you should forget about using dbExpress, try
some third party solutions, like suggested by the other reply.
Back to top
Hans Zandbergen
Guest





PostPosted: Wed Nov 08, 2006 3:22 pm    Post subject: Re: How to connect to mysql server Reply with quote

In article <4551576b (AT) newsgroups (DOT) borland.com>, kw (AT) nospam (DOT) com says...
Quote:


If you must use MySQL 5.x, then you should forget about using dbExpress, try
some third party solutions, like suggested by the other reply.


Or you can use libmySQL.dll directly (using implib and add the .lib to
your project) and the supplied headers. No easy to use data-aware
objects like this, but direct acces to the API.

I use MYSQL 5.0 and BCB 6 together.
Back to top
Renan
Guest





PostPosted: Wed Nov 08, 2006 3:43 pm    Post subject: Re: How to connect to mysql server Reply with quote

Quote:
I roughly recalled about I was having the same problem back then, but can't
really pinpoint where it arise - I was experimenting with countless
configuration and settings before I finally get dbExpress to work with
MySQL, so much trials untill my memory is all mixed up....

Here are somethings I could think of: (answers based on C++Builder6)
1) when configuring the TSQLConnection, make sure you choose the
ConnectionName instead of DriverName - the DriverName will change to MySQL
automatically if you select MySQLConnection from ConnectionName. It will
cause some problem if you do it the other way round, as far as I can
remember.

2) make sure your MySQL is not of version 4.1.x or newer. You might want to
get version 4.0.20 (which is what I'm using, along with C++Builder6), just
don't use 4.1.x or newer. I would recommend you download and install AppServ
2.5.1, which includes Apache server, PHP5, MySQL 4.0.20, and phpMyAdmin, all
configured to work fine together, as long as you are using the dbExpress
from C++Builder6. phpMyAdmin is a nice browser based GUI MySQL managing
tool.

most likely the "Unable to load libmysql.dll" problem is due to the MySQL
you are using is version 5.x, I guess. If that's the case, uninstall MySQL
5.x and search for all the libmysql.dll and delete them, then install MySQL
4.0.x (or AppServ 2.5.1, if you want a fully integrated web server and a
nice GUI tool for MySQL database management)(note: the web server is just
for use with phpMyAdmin, it has nothing to do with the MySQL server in the
package, so you can disable it after you installed AppServ, if you are not
going to use phpMyAdmin).

If you must use MySQL 5.x, then you should forget about using dbExpress, try
some third party solutions, like suggested by the other reply.



I am using MySQL 4.1, Windows 98 and CBuilder 6.0 (local - for development), and Windows NT 4(remote - that's how it must be after I finish my software) - I'm not going to use the remote server now, because it has mail and proxy settings for all people that work here. Now I'm going to use, in the development fase, or my local machine, or another remote server (Windows 98, in my room).
I like your solution, I will try AppServ 2.5.1. If something happens, I post here again.

Thanks for your help and tips.

Renan
Back to top
Renan
Guest





PostPosted: Wed Nov 08, 2006 3:47 pm    Post subject: Re: How to connect to mysql server Reply with quote

Quote:
Or you can use libmySQL.dll directly (using implib and add the .lib to
your project) and the supplied headers. No easy to use data-aware
objects like this, but direct acces to the API.

I use MYSQL 5.0 and BCB 6 together.

Can you post here an example of how to use this method (step-by-step, please)? Thats what I was trying to do.

I cannot use MySQL 5.0, because here it is win98(local) and winnt4 (remote server)


Renan
Back to top
Hans Zandbergen
Guest





PostPosted: Wed Nov 08, 2006 9:14 pm    Post subject: Re: How to connect to mysql server Reply with quote

In article <4551b5af$1 (AT) newsgroups (DOT) borland.com>,
nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com says...
Quote:

Can you post here an example of how to use this method (step-by-step, please)? Thats what I was trying to do.


This example contains a working unit, but may contain bugs and it is NOT
finised!

(1) Copy the headerfiles from the map mySQLServer\include to your
project/working dir (or include the dir in your path statement of your
project).

(2) Copy libmysql.dll to the output directory of your project.

(3) Use implib (implib libmysql.lib libmysql.dll)

(4) add libmysql.lib to your project.

(5) create a cpp+h file and add
#include "mysql/mysql.h" to the header and make a class like below (for
ease of use). (LSString is a special string class, but can be replaced
by AnsiString).


/** Classe for handling connection of a mySQL database.

*/
class LSmySQLConnection
{
private:
MYSQL* m_mySQL;
MYSQL_RES* m_mySQLresult;
bool m_connected;
LSString m_DataBaseName;
LSString m_HostName;
int m_Port;
LSString m_UserName;
LSString m_PassWord;
LSString m_Error;

public:
__property LSString DataBase=
{read=m_DataBaseName,write=m_DataBaseName};
__property LSString HostName={read=m_HostName,write=m_HostName};
__property LSString UserName={read=m_UserName,write=m_UserName};
__property LSString Password={read=m_PassWord,write=m_PassWord};
__property LSString Error={read=m_Error};
__property int Port={read=m_Port,write=m_Port};
__property bool Connected={read=m_connected};

public:
LSmySQLConnection();
virtual ~LSmySQLConnection();
int __fastcall Disconnect();
int __fastcall Connect();
int __fastcall Perform_Query(char* a_query);
unsigned __int64 __fastcall GetRecordCount();
unsigned long __fastcall GetFieldCount();
Variant __fastcall GetFieldValue(unsigned long a_fieldno);
int __fastcall GetFieldNames(LSStringList&lsl);
void __fastcall Begin();
int __fastcall GetFieldValue(int a_rownum, char* a_fieldname,Variant&
a_deData);

};

The cpp file contains then:

/-----------------------------------------------------------------------
----


#pragma hdrstop

#include "mysqlconnection.h"

//----------------------------------------------------------------------
-----

#pragma package(smart_init)


LSmySQLConnection::LSmySQLConnection()
{
m_mySQL = NULL;
m_mySQLresult = NULL;
m_connected = false;
m_Port = 0;
// mysql_library_init();
}

LSmySQLConnection::~LSmySQLConnection()
{ if(m_mySQL!=NULL)
Disconnect();
// mysql_library_end();
}

int __fastcall LSmySQLConnection::Disconnect()
{
mysql_close(m_mySQL);
m_mySQL = NULL;
m_connected = false;
return 0;
}

int __fastcall LSmySQLConnection::Connect()
{ m_Error.reset();
m_mySQL = mysql_init(NULL);
if(m_mySQL == NULL)
{ m_Error = "Kan mySQL in initialiseren mogelijk geheugen te kort";
return -1;
}
if(mysql_real_connect(m_mySQL, m_HostName,m_UserName,
m_PassWord,m_DataBaseName,m_Port,NULL, 0) == m_mySQL)
{ m_connected = true;
//mysql_select_db(m_mySQL,m_DataBaseName);
return 0;
}else
m_Error = mysql_error(m_mySQL);
return -2;
}

int __fastcall LSmySQLConnection::Perform_Query(char* a_query)
{ m_Error.reset();
if(m_mySQLresult != NULL)
{
mysql_free_result(m_mySQLresult);
m_mySQLresult = NULL;
}
if(m_connected && (m_mySQL!=NULL))
{
mysql_query(m_mySQL,a_query);
m_mySQLresult = mysql_store_result(m_mySQL);
if((m_mySQLresult==NULL)&&(mysql_errno(m_mySQL)))
{ m_Error = mysql_error(m_mySQL);
return -2;
}
return mysql_affected_rows(m_mySQL);
}
return -1;
}

unsigned __int64 __fastcall LSmySQLConnection::GetRecordCount()
{
if(m_mySQLresult!=NULL)
return mysql_num_rows(m_mySQLresult);
return 0;
}

unsigned long __fastcall LSmySQLConnection::GetFieldCount()
{
if(m_mySQLresult!=NULL)
return mysql_field_count(m_mySQL);
return 0;
}

Variant __fastcall LSmySQLConnection::GetFieldValue(unsigned long
a_fieldno)
{
MYSQL_ROW row;
if(m_mySQLresult!=NULL)
{
if(a_fieldno < GetFieldCount())
{ row = mysql_fetch_row(m_mySQLresult);
if(row == NULL)
{ m_Error = mysql_error(m_mySQL);
return 0;
}
return row[a_fieldno];
}
}
return "NULL";
}

int __fastcall LSmySQLConnection::GetFieldNames(LSStringList& lsl)
{
lsl.Clear();
MYSQL_FIELD*fields;
unsigned int numfields,index;

if(m_mySQLresult!=NULL)
{
numfields = mysql_num_fields(m_mySQLresult);
fields = mysql_fetch_fields(m_mySQLresult);
for(index=0;index<numfields;index++)
lsl.Add(fields[index].name);
return 0;
}
return -1;
}

void __fastcall LSmySQLConnection::Begin()
{
if(m_mySQLresult!=NULL)
{
mysql_data_seek(m_mySQLresult,0);
}
}

/**
Ophalen van een waarde uit een databaseveld.

@param a_rownum nummer van de row (record) welke je wilt hebben.
@param a_fieldname naam van het veld welke je wilt hebben.
@param a_deData Een Variant waar de data inkomt, bij fout blijft deze
onveranderd.

@return foutcode
@retval 0 alles is goedgegaan, a_deData bevat een nieuw waarde
@retval -1 foutief recordnummer opgegeven.
@retval -2 fout bij ophalen record opgetreden zie Error property.
@retval -3 Veldnaam niet gevonden.
@retval -4 Result is NULL

*/
int __fastcall LSmySQLConnection::GetFieldValue(int a_rownum, char*
a_fieldname,Variant& a_deData)
{
MYSQL_ROW row;
MYSQL_FIELD*fields;
unsigned int numfields,index;

if(m_mySQLresult!=NULL)
{
if(a_rownum >= mysql_num_rows(m_mySQLresult))
return -1;

numfields = mysql_num_fields(m_mySQLresult);
fields = mysql_fetch_fields(m_mySQLresult);
for(index=0;index<numfields;index++)
{ if(stricmp(fields[index].name,a_fieldname)==0)
{
mysql_data_seek(m_mySQLresult,a_rownum);
row = mysql_fetch_row(m_mySQLresult);
if(row == NULL)
{ m_Error = mysql_error(m_mySQL);
return -2;
}
a_deData = row[index];
return 0;
}
}
return -3;
}
return -4;
}

///--- end of unit ------


Hoping this will help you.

Hans Zandbergen
Back to top
kw
Guest





PostPosted: Thu Nov 09, 2006 8:50 am    Post subject: Re: How to connect to mysql server Reply with quote

"Renan" <nospam_dot_gulbrrs (AT) gmail_dot_ (DOT) com> 撰寫於郵件新聞:4551b4b6$1 (AT) newsgroups (DOT) borland.com...
Quote:
I am using MySQL 4.1,

Ah, I see, MySQL 4.1.x is not working with dbExpress. Although someone
pointed out to me, during my search for solution back then, that the
particular version that is not supported is 4.1.7, I found out that as long
as it is 4.1.x it's not supported. I am sure 4.0.20 is working, since I'm
using it now. Someone else told me 4.0.26 is working too, but I didn't find
any AppServ version packaged with 4.0.26.

Quote:
Windows 98 and CBuilder 6.0 (local - for development), and Windows NT
4(remote
- that's how it must be after I finish my software) - I'm not going to use
the
remote server now, because it has mail and proxy settings for all people
that
work here. Now I'm going to use, in the development fase, or my local
machine,
or another remote server (Windows 98, in my room).
I like your solution, I will try AppServ 2.5.1. If something happens, I
post here again.

so you are designing for it to work in an intranet. Remeber to make a
fuction for the clients (your app) to be able to choose the server, not
hardcode it in the TSQLConnection component... I have made this mistake and
was spending an awful lot of time wondering "Why oh why...?". I know it's a
silly mistake, but I have been stung hard enough to want to mention this
here...hee hee. ;-D

Also, it's fine to use AppServ if you are developing locally, but you have
to check with your IT Support dept. to see if you can have a webserver
running at your remote server, for the real thing. If not you will have to
dig out the old MySQL 4.0.x from the official website archive.

Quote:
Thanks for your help and tips.

glad I could help. :-)

Quote:
Renan
Back to top
Mark Guerrieri
Guest





PostPosted: Sat Nov 11, 2006 9:10 am    Post subject: Re: How to connect to mysql server Reply with quote

Quote:
Now, I don't know almost anything about database (I know a little about
paradox using bde). I need to know how do I connect to a MySQL server,
local
and remote. Local is just for testing, and remote is for people here at
work
to use.


Install MyODBC, then use TADOConnection/TADOQuery/etc...

Mark
Back to top
Dmitry Konnov
Guest





PostPosted: Sat Nov 25, 2006 4:44 pm    Post subject: Re: How to connect to mysql server Reply with quote

Renan,

check
www.microolap.com
for MySQL access components.

Dmitry
Back to top
Anthony
Guest





PostPosted: Sun Apr 08, 2007 8:10 am    Post subject: Re: How to connect to mysql server Reply with quote

i followed these steps and i get the error msg:

'[Linker Error] 'C:\PROGRAM
FILES\BORLAND\CBUILDER6\PROJECTS\Z2\LIBMYSQL.LIB' contains invalid OMF
record, type 0x21 (possibly COFF)'

i tried using the command line:

'coff2omf libmysql.lib libmysql_b6.lib'

and added almost every MySQL file i could find and still get the error msg,
any ideas on what im doing wrong here???
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.