Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    68
    Rep Power
    5
    Hi,
    here is a video tutorial about Delphi + MySQL + SQLConnection it's in russian but you can get the idea just from watchingit.

    Dimiter.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    68
    Rep Power
    5
    Hi,
    there is Params property of the SQLConnection object.

    Dimiter
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep Power
    0
    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?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    68
    Rep Power
    5
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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. ;(
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    68
    Rep Power
    5
    Hi,
    here are some expamples. You can try with them.

    Dimiter.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep Power
    0
    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.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep Power
    0
    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
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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 + "'"
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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!!!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo