Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 5 - Using Delphi with MySQL
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Using Delphi with MySQL
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 20
    2006-10-25

    Table of Contents:
  • Using Delphi with MySQL
  • Required Tools
  • Setting up the Connector
  • The Application
  • Form Two

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Delphi with MySQL - Form Two


    (Page 5 of 5 )

    There are two buttons on form2. The first button inserts a new article and the second button is used to update an article.

    Add the following code to the first button:

    procedure TForm2.BitBtn1Click(Sender: TObject);
    begin
    form1.q1.close;
    form1.q1.SQL.Text:='INSERT INTO articles (auth,title,article_body,date_published) values
    ('''+edit1.text+''','''+edit2.Text+''','''+memo1.lines.
    Text+''','''+edit3.text+''')';
    form1.q1.ExecSQL;
    showmessage('New record inserted.');
    end;

    The code is straightforward. It runs a query that inserts a new article based on the values entered into the form components.

    Add the following code to the second button:

    procedure TForm2.Button1Click(Sender: TObject);
    begin
    form1.q1.close;
    form1.q1.SQL.Text:='UPDATE articles SET
    auth=:aname,title=:atitle,article_body=:sbody,date_published=
    :apubdate WHERE aid=:Aid';
    form1.q1.Parameters.ParamByName('aname').Value:=edit1.text;
    form1.q1.Parameters.ParamByName('atitle').Value:=edit2.text;
    form1.q1.Parameters.ParamByName('sbody').Value:=memo1.Lines.Text;
    form1.q1.Parameters.ParamByName('apubdate').Value:=edit3.text;
    form1.q1.Parameters.ParamByName('Aid').Value:=id;
    form1.q1.ExecSQL;
    showmessage('All Updated.');
    end;

    This code is straightforward as well. It only updates the article sent over from form one and sends the updated version back to the database. The important thing here is the "aid" value in the "where" clause of the query. It identifies the article that you want changed. If you don't include a where clause, every article in the database will be overwritten with the values that you intended only for this article. Below is a test run of the application:

    Conclusion

    This is just a simple example intended to demonstrate how to connect and interact with a MYSQL database. It is not as easy as when creating a single user database, but it gives your applications a lot more performance power. It also makes it possible for you to write thin client applications that can be used on a large network. That is something you cannot do with a single user database.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · MYSQL is a very powerful and easy to use database server that is freely available...
       · It's a good article, but how 'bout the deployment? How to do that?
     

    DELPHI-KYLIX ARTICLES

    - Loading an XML Document into the DOM
    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek