Advertisement
stevennathaniel

Koneksi Ke MySQL

Jan 29th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 KB | None | 0 0
  1. unit Latihan2unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, mysql55conn, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, EditBtn;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     DateEdit1: TDateEdit;
  18.     Edit1: TEdit;
  19.     Edit2: TEdit;
  20.     Edit3: TEdit;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     Label3: TLabel;
  24.     Label4: TLabel;
  25.     Label5: TLabel;
  26.     MySQL55Connection1: TMySQL55Connection;
  27.     procedure Button1Click(Sender: TObject);
  28.     procedure DateEdit1Change(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure Label2Click(Sender: TObject);
  31.   private
  32.     { private declarations }
  33.   public
  34.     { public declarations }
  35.   end;
  36.  
  37. var
  38.   Form1: TForm1;
  39.  
  40. implementation
  41.  
  42. {$R *.lfm}
  43.  
  44. { TForm1 }
  45.  
  46. procedure TForm1.Label2Click(Sender: TObject);
  47. begin
  48.  
  49. end;
  50.  
  51. procedure TForm1.DateEdit1Change(Sender: TObject);
  52. begin
  53.  
  54. end;
  55.  
  56. procedure TForm1.Button1Click(Sender: TObject);
  57. begin
  58.  
  59.    // perintah untuk menutup form & memutuskan koneksi ke server
  60.  
  61.    MySQL55Connection1.Close;
  62.    MySQL55Connection1.Free;
  63.    close;
  64.  
  65. end;
  66.  
  67. procedure TForm1.FormCreate(Sender: TObject);
  68. begin
  69.  
  70.   // Mengkoneksikan form ke database MySQL pada saat form di load
  71.   // Sehingga Label paling atas akan menampilkan status terkoneksi
  72.  
  73.    // Isikan data untuk login ke server
  74.    MySQL55Connection1.DatabaseName:='pdam';
  75.    MySQL55Connection1.UserName:='root';
  76.    MySQL55Connection1.Password:='kucing';
  77.  
  78.    // Buka koneksi ke server
  79.    MySQL55Connection1.Open;
  80.  
  81.    if MySQL55Connection1.Connected then
  82.    begin
  83.  
  84.      // Kalau terkoneksi tampilkan pesan ini di label
  85.      Label1.Caption:='Terkoneksi ke MySQL';
  86.    end;
  87.  
  88.  
  89.  
  90.  
  91. end;
  92.  
  93. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement