Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 11th, 2012, 09:13 PM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
MySQL Connection

Hello everyone!

So, I just bought Delphi XE2. I come from a visual studio background, so getting used to things was pretty easy.

Anyways, I'm trying to connect my VCL application to my MySQL database. I have already created the database/table/columns, etc.

I used them in my VB.NET application.

So, my question is, how can I connect my Delphi application to my MySQL database?

Could someone provide a detailed tutorial? I'm willing to pay paypal money to have this completed. But, you'll have to wait about 2 weeks until I receive my credit card.

Reply With Quote
  #2  
Old May 12th, 2012, 04:04 AM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
here is a video tutorial about Delphi + MySQL + SQLConnection it's in russian but you can get the idea just from watchingit.

Dimiter.

Reply With Quote
  #3  
Old May 12th, 2012, 09:16 AM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Thank you, but after following his video, when I try to login, it says

DBX Error: Driver could not be properly initialized. Client library may be missing, not installed properly, of the wrong version, or the driver maybe be missing from the system path...

Reply With Quote
  #4  
Old May 13th, 2012, 12:45 AM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Ok, so I fixed the above error and I successfully connected to my server and database.

Now, what is the connection string for delphi so that I can make some sort of login?

I want it to check if a column exists when the form loads.

Reply With Quote
  #5  
Old May 13th, 2012, 01:46 AM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
there is Params property of the SQLConnection object.

Dimiter

Reply With Quote
  #6  
Old May 14th, 2012, 02:56 PM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by Dimixx
Hi,
there is Params property of the SQLConnection object.

Dimiter


ok so in visual studio, the first thing I do is start the connection:

Dim Connection As MySqlConnection
Connection = New MySqlConnection
Connection.ConnectionString = "server=server; user id=userid; password=password; database=database"
Try
Connection.Open()
Catch MyError As MySqlException
MsgBox("No Connection!")
End Try
Dim MyAdapter As New MySqlDataAdapter
Dim SQLQuery = "SELECT * FROM Table WHERE Row = '" TextBox1.Text
Dim MyCommand As New MySqlCommand()
MyCommand.Connection = Connection
MyCommand.CommandText = SQLQuery
MyAdapter.SelectCommand = MyCommand
Dim MyData As MySqlDataReader
MyData = MyCommand.ExecuteReader
If MyData.HasRows = False Then
MsgBox("Password Not Found!")
Else
MsgBox("Welcome!")
End If

What would be the equivalent in delphi?

Reply With Quote
  #7  
Old May 15th, 2012, 04:04 AM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
First. Did you look in the params property of the SQLConnection object. There are the properties you need to set : user_name, password, database, etc.
In the code that you give us you create the connection dynamicly in your code. You can do this here too, but it's way more easy to make it in design time. After you fill the params you can try if it work with the Connected property. If you can set it to true it works, otherwise it fires an error message. After that you can use SQLDataSet or SQLquery to write your SQL there. For the SQLDataSet it's the CommandText property for the SQLQuery the SQL property. You have not to forget to set the SQLConnection property to 'SQLConnection1'(or what ever your SQLConnection is named) of the chosen by you component.

Dimiter.

Reply With Quote
  #8  
Old May 15th, 2012, 10:54 AM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Thank you. I understand. I have filled my sql parameters out correctly and I can connect to my database with no errors.

now, i just have to use the sql dataset's, etc.

i thought i still had to program code, but it's already done for me with the tsqlconnection. thank you, i'll get started.

Reply With Quote
  #9  
Old May 15th, 2012, 11:38 AM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Do you think you can provide some code to insert my editbox contents into mysqldatabase?

i've searched around for sqlquery in delphi, but no luck getting it right. ;(

Reply With Quote
  #10  
Old May 16th, 2012, 02:46 AM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
here are some expamples. You can try with them.

Dimiter.

Reply With Quote
  #11  
Old May 16th, 2012, 11:51 AM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by Dimixx
Hi,
here are some expamples. You can try with them.

Dimiter.


thank you. that seems to be what i'm looking for. one more thing...

i've been trying to change the edit1keypress event, but I always get an error and I can't launch my program.

what i want is when i press enter on my edit1 box, a message box appears and says welcome.

http://forum.delphi-treff.de/showthread.php?18023-edit-enter

http://www.delphipraxis.net/70820-edit-enter.html

http://www.programmersheaven.com/mb/delphikylix/329422/329422/pressing-enter-in-editbox-to-perform-action/

none of these work in delphi xe2.

Reply With Quote
  #12  
Old May 16th, 2012, 01:45 PM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by Ritzky
thank you. that seems to be what i'm looking for. one more thing...

i've been trying to change the edit1keypress event, but I always get an error and I can't launch my program.

what i want is when i press enter on my edit1 box, a message box appears and says welcome.

http://forum.delphi-treff.de/showthread.php?18023-edit-enter

http://www.delphipraxis.net/70820-edit-enter.html

http://www.programmersheaven.com/mb/delphikylix/329422/329422/pressing-enter-in-editbox-to-perform-action/

none of these work in delphi xe2.


nvm i got it working. now I can work on the sql part. thank you

Reply With Quote
  #13  
Old May 17th, 2012, 12:36 PM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
ok, i've tried and I just can't get it working. ive googled for hours and used code, but I always get an error.

ive connected to my server and database. but when i want to SELECT * FROM TABLE, I just can't get it working. can someone post example code?

here's what i'm trying to do (this is vb.net code)

Dim SQLQuery = "SELECT * FROM TABLE WHERE ROW = '" + TextBox1.Text + "'"

Reply With Quote
  #14  
Old May 17th, 2012, 01:00 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I am not knowledgeable on MYSQL itself; but I am very experienced with SQL.

Two things:
1.
I have never come across a SQL syntax that allows a where clause followed by the
word ROW (I am assuming you do not have a column named "ROW").
Some databases will allow WHERE (COLA,COLB) = (ValueA,ValueB)

2.
Using a construct like
WHERE COL_X = '" + TextBox1.Text + "'"
Leaves you vulnerable to a SQL injection attack.
It is safer to use a parametrized query
WHERE COL_X = :PARAM_X

Reply With Quote
  #15  
Old May 18th, 2012, 02:13 PM
Ritzky Ritzky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 11 Ritzky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 4 sec
Reputation Power: 0
Ok, so I added the TSQLConnection and configured it, the Table, and the Dataset. Still, everytime I input the code, my words get underlined, even though I just copied and pasted from another site that says it works.

ive tried editing it to get rid of the red lines, but then it just never connects. darn delphi -_-...

at least once I get past this, it will be easy for me lol. it's really similar to visual basic apart from the mysql connection stuff.

someone post the code to make it work!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > MySQL Connection

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap