• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

Delphi/Kylix with MySql

Can any one send me sample code/tutorial/components for using delphi/kylix and MySql
thanks
venks
0
venks
Asked:
venks
1 Solution
 
sauliteCommented:
with Delphi i have tried, tru ODBC, you need to download ODBC driver for MySQL. then use standard ODBC components.

I could give you real working example after few days (i dont have delphi right now, but the example that worked i have left at my friend's home PC :))

maybe after some 12h.
0
 
intheCommented:
hi,
you can use odbc as above but i prefer to use directly to mysql db using one of the mysql units/comps as sometimes end users may not have the odbc drivers installed etc..
this is one of the best component ones and works on all versions of windows.

http://productivity.org/projects/mysql/

also you can get the freeware source code for winmysql
(it was wrote in delphi using the units im mentioning above)it is a front-end / db-manager thing,one of the better ones for mysql,and with the source you can modify it to suit..
http://www.winmysql.com/page4.html

i also have a couple of demos of other mysql units etc if you want them let me know as i dont know where i got them though the above stuff should cover it all anyways.
Regards
Barry
0
 
DragonSlayerCommented:
For Delphi, I find native access to mySQL is much faster... http://www.zeoslib.org

It's free :)
0
 
sauliteCommented:
OK. here would be my example.
It executes query, and prints space seperated values into the memo.
Needed lybraries: MyOLEDB, MyODBC, can be found at www.mysql.com

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ADODB, Db;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ADOConnection1: TADOConnection;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
 ADOConnection1.ConnectionString:='DSN=UzeruDB';
// use 'ODBC Data Sources' in Control panel, to create a System DSN.'  
// you should set Driver('MySQL'), DSN Name (Used here), hostname ('localhost', or server IP), Database Name ('MYSQL').  
 Memo1.Align:=alBottom;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOConnection1.Open; // only if you need to ask user for username/pass
end;

procedure TForm1.Button2Click(Sender: TObject);
var RecSet: _Recordset;
    S: string;
    i: integer;
    j: integer;
begin
  RecSet:=ADOConnection1.Execute(Edit1.Text);
  S:=' | ';
  for i:=0 to RecSet.Fields.Count-1 do begin
    S:=S+RecSet.Fields[i].Name+' | ';
  end;
  Memo1.Lines.Add(S);
  Memo1.Lines.Add(''); //empty line
  for j:=0 to RecSet.RecordCount-1 do begin
    S:=' | ';
    for i:=0 to RecSet.Fields.Count-1 do begin
      S:=S+RecSet.Fields[i].Value+' | ';
    end;
    Memo1.Lines.Add(S);
    Memo1.Lines.Add('');
    RecSet.MoveNext;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  ADOConnection1.Close;
end;

end.
0
 
venksAuthor Commented:
thanks
venks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now