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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| unit bdConnect;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Bde.DBTables, Vcl.Grids, Vcl.DBGrids,
Data.DB, Data.DBXMySQL, Data.FMTBcd, Vcl.ExtCtrls, Vcl.DBCtrls,
iniFiles, strUtils,mysql,
Vcl.StdCtrls, Datasnap.DBClient, Datasnap.Provider, Data.SqlExpr;
type
TForm13 = class(TForm)
DBGrid1: TDBGrid;
SQLConnection1: TSQLConnection;
SQLDataSet1: TSQLDataSet;
DataSetProvider1: TDataSetProvider;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
Query1: TQuery;
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
mySQLConnection : PMYSQL;
myRow : PMYSQL_ROW;
myRES : PMYSQL_RES;
aStr: String;
public
{ Déclarations publiques }
mysql: PMysql;
req: String;
procedure sqlConnect;
procedure sqlClose;
procedure bdCon;
procedure affTable;
end;
var
Form13: TForm13;
implementation
CONST
dbname='hrTest1';
{$R *.dfm}
//var
//mySQLConnection : PMYSQL;
//myRow : PMYSQL_ROW;
//myRES : PMYSQL_RES;
//aStr: String;
//i,j : cardinal;
//init la sqlConn
procedure TForm13.sqlConnect;
begin
mySQLConnection := mysql_init(nil);
end;
//fermeture de la connexion
procedure TForm13.sqlClose;
begin
mysql_close(mySQLConnection);
end;
//connexion a la BD
procedure TForm13.bdCon;
begin
if mysql_real_connect(mySQLConnection, 'localhost', 'fp', 'pass', 'hrTest1', 0, nil, 0) <> nil then begin
//connvµect reussie
end else begin
//echec connect
end;
end;
//afficher les tables de la BD
procedure TForm13.affTable;
var
i,j : integer;
begin
myRES := mysql_list_tables(mySQLConnection,nil);
if myRES <> nil then begin
for i := 0 to myRES^.row_count-1 do begin
myROW := mysql_fetch_row(myRES);
for j := 0 to mysql_num_fields(myRES) - 1 do begin
aStr := myROW^[j];
ListBox1.Items.Add(aStr);
end;
end;
mysql_free_result(myRES);
end;
end;
//function ajout(req:String):boolean;
//Query1.SQL.Clear;
//Query1.SQL.Add(req);
//Query1.ExecSQL; //Execute la requête
//end;
//function update(req:String):boolean;
//Query1.SQL.Clear;
//Query1.SQL.Add(req);
//Query1.ExecSQL
//end;
procedure TForm13.Button1Click(Sender: TObject);
begin
affTable;
end;
end. |
Partager