In the last post, i show you how to Install. Now i wanna try to show you “How make connection to MySql with this Component.

1.Run Your Delphi Application

2.In Component Pallete find Zeos Access ( you can use left arrow and right arrow to navigate this )

3.Drag and drop component

—> Choose Zconnection:TZConnection, you can named this component as you like, ex: MyConn

Ok! for use the component and drop to your Form Design has finish.

Now for next step

1.Click twice your Form Design, you will find

 

procedure TForm1.FormCreate(Sender: TObject);

[type or paste the code here]

end.

Insert this code in [type or paste the code here]


ShortDateFormat:='dd/mm/yyyy';
     DecimalSeparator:='.';
     myConn.Protocol:='mysql';
     myConn.HostName:='localhost';
     myConn.Port:=StrToInt('3306');
     myConn.User:='[your user name to login MySql, default is root]';
     myConn.Password:='[your password, but if you uses Zeos you must empty you password to login MySql]';
     myConn.Database:='[your database]';
     try
        myConn.Connect;
     except on E:exception do
       begin
            MessageDlg('Koneksi database gagal!!!'#13+E.Message, mtError,[mbOk],1);
            Close;
       end;
     end;

end;

Save your project, and put libmysql40.dll[default included in your Zeos Package] in directory which contain your .exe file. Now compile your application or push F9.

Popularity: 62%