Topic: Other MySQL

Hi all. Is it possible to connect an existing database such as BASE on the server 192.168.0.1 to the BASE2 database on 192.168.2.1 ??? and get data from there

Re: Other MySQL

You cannot connect to two databases at the same time, but you can connect to different databases in turn, saving the data received from the first database in local files for later transfer to the second database.

Визуальное программирование: блог и телеграм-канал.

Re: Other MySQL

Well, tell me the button script to connect to another database in the program to make some changes or direct me in the right direction! : ) Thanks

Re: Other MySQL

{$MySQL disable_connectdialog}

var
  // системные переменные
  SQLCon: TMyConnection; // соединение с базой

function ConnectToDB(AServer: string; APort: integer; ADataBase: string'; AUsername: string'; APassword: string): boolean;
// подключение к Базе данных; Возвращает True при успешном подключении; 
begin
  SQLCon.Server := AServer;
  SQLCon.Port := APort;
  SQLCon.Database := ADataBase;
  SQLCon.Username := AUsername;
  SQLCon.Password := APassword;
  try
    SQLCon.Connect;
    result := SQLCon.Connected;
  except
    result := False;
  end;
end;

procedure InitSystemVar;
var
  i: integer;
  tmpForm: TAForm;
begin
  for i := 0 to Screen.FormCount - 1 do
  begin
    tmpForm := TAForm(Screen.Forms[i]);
    FindC(tmpForm, 'MySQLConnection', SQLCon, False);
    if SQLCon <> nil then
      break;
  end;
end;

procedure FindC(AForm: TAForm; AName: string; var AComponent: TComponent; ACheck: boolean = True);
// поиск компонента на форме с контролем
begin
  AComponent := AForm.FindComponent(AName);
  if ACheck and (AComponent = nil) then
    ShowMessage('Не найден компонент ' + AForm.Name + '.' + AName);
end;

begin
  InitSystemVar;
end.

Use the ConnectToDB() to connect to the desired server.

ConnectToDB('192.168.0.1',3306,'myBase','admin','password')
Визуальное программирование: блог и телеграм-канал.

Re: Other MySQL

paste this script separately or in Form1 ? I just have a connection to the 1 database..




procedure Form1_OnShow (Sender: string; Action: string);
var
   //////////////////////////////////////////////////////////////////////////////////////////////////Создаем переменые для меню
   //////////////////////////////////////////////////////////////////////////////////////////////////Создаем переменые меню
   MyItem1: TMenuItem;//Файл
   MyItem2: TMenuItem;//О программе
   MySubItem3: TMenuItem;//Файл - закрыть
   ok: boolean;
   var  vreminder: string; vapps : integer;

   ////////////////////////////////////////////////////////////////////////////////////////////////////
begin
     frmWait.Show;
     Application.ProcessMessages;
     {$MySQL disable_connectdialog}
     Form1.MySQLConnection.Server := '10.24.221.20';
     Form1.MySQLConnection.Port := 3306;
     Form1.MySQLConnection.Username := 'BASE';
     Form1.MySQLConnection.Password := '123123';
     Form1.MySQLConnection.Database := 'newbase';
       try
       // попытка 1...
    Form1.MySQLConnection.Connect;
    ok:=true;
  except
      end;
  if not ok then                                           
    begin                                               
      Form1.MySQLConnection.Server := '192.168.1.85';
      Form1.MySQLConnection.Port := 3306;
      Form1.MySQLConnection.Username := 'BASE';
      Form1.MySQLConnection.Password := '123123';
      Form1.MySQLConnection.Database := 'newbase';
      try
            // попытка 2...
        Form1.MySQLConnection.Connect;
        ok:=true;
        except
        end;
    end;
       if ok then
    begin
    UpdateDatabase('');
    end else
    begin
     frmWait.Close;
     ShowMessage('Проверте подключение к базе данных');
     Form1.Close;
end;
     if Form1.MySQLConnection.Connected then
     UpdateDatabase('');

Re: Other MySQL

There is only one connection to the base.


My script is universal, it is not tied to the names of the project forms.


procedure Form1_OnShow (Sender: string; Action: string);
var
  ok: boolean;
begin
  frmWait.Show;
  Application.ProcessMessages;
  ok := ConnectToDB('10.24.221.20',3306,'myBase','admin','password');
  if not ok then
    ok := ConnectToDB('192.168.1.85',3306,'myBase','admin','password');
  if ok then
    UpdateDatabase('')
  else
  begin
     frmWait.Close;
     ShowMessage('Проверьте подключение к базе данных');
     Form1.Close;
  end;
end;

And, by the way, on the topic of copy-paste in the program code:https://k245.ru/mvdb/lechenie-kopipasta.html

Визуальное программирование: блог и телеграм-канал.