Topic: MySQL database connection button.
Hello, friends! Help with the question. For example: I work with the SQLite database, but there is also a MySQL database and I would like to connect to it through the button with a script in the program. But how can I get data from the MySQL database to which I connected with the button, if there is Form1.TableGrid1? Is it possible? Thank.
I connect to the database like this:
procedure Form1_Button9_OnClick (Sender: TObject; var Cancel: boolean);
var
MySQL: TMyConnection;
begin
MySQL := TMyConnection.Create(Form1);
try
MySQL.Options.UseUnicode := True;
MySQL.Server := '127.0.0.1';
MySQL.Port := 3306;
MySQL.Username := 'user';
MySQL.Password := 'pass';
MySQL.Database := 'base';
MySQL.LoginPromt := False;
try
MySQL.Connect;
except
ShowMessage('Can''t connect to database.');
end;
if MySQL.Connected then
begin
ShowMessage ('DB OK');
end;
finally
//MySQL.Free;
end;
end;
With Google translator.