The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
MySQL Connection
Discuss MySQL Connection in the Delphi Programming forum on Dev Shed. MySQL Connection Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 11th, 2012, 09:13 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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.
|

May 12th, 2012, 04:04 AM
|
|
Contributing User
|
|
Join Date: Jan 2010
Posts: 68
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.
|

May 12th, 2012, 09:16 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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...
|

May 13th, 2012, 12:45 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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.
|

May 13th, 2012, 01:46 AM
|
|
Contributing User
|
|
Join Date: Jan 2010
Posts: 68
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
|
|
|
Hi,
there is Params property of the SQLConnection object.
Dimiter
|

May 14th, 2012, 02:56 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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?
|

May 15th, 2012, 04:04 AM
|
|
Contributing User
|
|
Join Date: Jan 2010
Posts: 68
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.
|

May 15th, 2012, 10:54 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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. 
|

May 15th, 2012, 11:38 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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. ;(
|

May 16th, 2012, 02:46 AM
|
|
Contributing User
|
|
Join Date: Jan 2010
Posts: 68
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
|
|
Hi,
here are some expamples. You can try with them.
Dimiter.
|

May 16th, 2012, 11:51 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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.
|

May 16th, 2012, 01:45 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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
|

May 17th, 2012, 12:36 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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 + "'"
|

May 17th, 2012, 01:00 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
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
|

May 18th, 2012, 02:13 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
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!!! 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|