Bonjour,

je fait un essai de connection à la base de données MySQL. Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
procedure TForm1.Button1Click(Sender: TObject);
begin
  // Check if we have an active connection. If so, let's close it.
  if MySQL50Connection1.Connected then begin
    SQLTransaction1.Active := False;
    MySQL50Connection1.Close;
  end;
  // Set the connection parameters.
  MySQL50Connection1.HostName := '127.0.0.1' ;
  MySQL50Connection1.UserName := 'root';
  MySQL50Connection1.Password := '';
  MySQL50Connection1.DatabaseName := 'mysql'; // MySQL is allways there!
  MySQL50Connection1.Open;
 
  // First lets get a list of available databases.
  if MySQL50Connection1.Connected then begin
    SQLQuery1.SQL.Text := 'SHOW DATABASES' ;  // ; 'SELECT * FROM user';
 
    SQLQuery1.Open;
    while not SQLQuery1.EOF do begin
      DatabaseComboBox.Items.Add(SQLQuery1.Fields[0].AsString);
      //DatabaseComboBox.Items.Add(SQLQuery1.FieldByName('host').AsString) ;
      SQLQuery1.Next;
    end;
    SQLQuery1.Close;
  end;
 
end;
Si je laisse SHOW DATABASES il me signale une erreur de syntaxe (alors que si j'utilise cette requête dans phpMyAdmin ça fonctionne) près de ''.
Si je mets SELECT * FROM user ça fonctionne.

Est-ce moi qui fait une erreur ou est-ce que je n'ai pas tout compris (peut-être une option de TSQLQuery ou autre) ?

J'ai pris l'exemple de http://wiki.lazarus.freepascal.org/MySQLDatabases et j'ai le même problème.