ZEOS is one component package to connect delphi with mysql database. to be able to interact with MySQL database ZEOS requires a library file that is libmysql.dll, the file can be obtained at the time we install heidisql. File position is located in C: \ Program Files \ HeidiSQL \libmysql.dll
we can download heidisql www.heidisql.com site.
ok.. next..

  • create new application
  • save all to c:\myproject\
  • put libmysql.dll to c:\myproject\
  • put tzconnection from zeos pallet to form
  • add button
  • change button1 caption : connect
  • on button1 click write this code
procedure TForm1.Button1Click(Sender: TObject);
begin
   // configuration pre connect
    ZConnection1.Disconnect;
    ZConnection1.HostName:='localhost';
    ZConnection1.Protocol:='mysql';
    ZConnection1.User:='root';
    ZConnection1.Password:='';
    ZConnection1.Port:=3306;
    ZConnection1.LoginPrompt:=false;

    // try connect to localhost
    try
     ZConnection1.Connect;
     showmessage('connecting success..!')
    except
     showmessage('connecting fail..!')
    end;
end;

 

 

source code unit

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes,
  Graphics, Controls, Forms,
  Dialogs, StdCtrls, ZConnection;

type
  TForm1 = class(TForm)
    ZConnection1: TZConnection;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   // configuration pre connect
    ZConnection1.Disconnect;
    ZConnection1.HostName:='localhost';
    ZConnection1.Protocol:='mysql';
    ZConnection1.User:='root';
    ZConnection1.Password:='';
    ZConnection1.Port:=3306;
    ZConnection1.LoginPrompt:=false;

    // try connect to localhost
    try
     ZConnection1.Connect;
     showmessage('connecting success..!')
    except
     showmessage('connecting fail..!')
    end;
end;

end.

 

form  code

object Form1: TForm1
  Left = 192
  Top = 124
  Width = 870
  Height = 500
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 208
    Top = 96
    Width = 75
    Height = 25
    Caption = 'Connect'
    TabOrder = 0
    OnClick = Button1Click
  end
  object ZConnection1: TZConnection
    Left = 96
    Top = 88
  end
end
Print Friendly