Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program ProjectMysqlADO;
- {$APPTYPE CONSOLE}
- uses
- ActiveX,
- DB,
- ADODB,
- SysUtils;
- const
- //the connection string
- StrConnection='Driver={MySQL ODBC 3.51 Driver};Server=%s;Database=%s;User=%s; Password=%s;Option=3;';
- var
- AdoConnection : TADOConnection;
- procedure SetupConnection(DataBase:String);//Open a connection
- begin
- Writeln('Connecting to MySQL');
- AdoConnection:=TADOConnection.Create(nil);
- AdoConnection.LoginPrompt:=False;//dont ask for the login parameters
- AdoConnection.ConnectionString:=Format(StrConnection,['your_server',DataBase,'your_user','your_password']);
- AdoConnection.Connected:=True; //open the connection
- Writeln('Connected');
- end;
- procedure CloseConnection;//Close an open connection
- begin
- Writeln('Closing connection to MySQL');
- if AdoConnection.Connected then
- AdoConnection.Close;
- AdoConnection.Free;
- Writeln('Connection closed');
- end;
- procedure SearchPersonnel(Nom:String);//Search for an employee in the database
- var
- AdoQuery : TADOQuery;
- begin
- AdoQuery:=TADOQuery.Create(nil);
- try
- AdoQuery.Connection:=AdoConnection;
- AdoQuery.SQL.Add('SELECT * FROM Temploye WHERE nom='+Nom);
- AdoQuery.Open;
- while not AdoQuery.eof do
- begin
- Writeln(format('%s %s %s',[AdoQuery.FieldByname('id').AsString,AdoQuery.FieldByname('nom').AsString,AdoQuery.FieldByname('prenom').AsString]));
- AdoQuery.Next;
- end;
- finally
- AdoQuery.Free;
- end;
- end;
- begin
- CoInitialize(nil); // call CoInitialize()
- try
- Writeln('Init');
- try
- SetupConnection('Dm'); //open the connection pointing to the Mydb database
- SearchPersonnel('nom'); //search for an employee by his name
- CloseConnection; //close the connection
- except
- on E : Exception do
- Writeln(E.Classname, ': ', E.Message);
- end;
- Readln;
- finally
- CoUnInitialize; // free memory
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement