Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$mode objfpc}
- program test;
- uses mysql50, SysUtils;
- var
- db : PMYSQL;
- res : PMYSQL_RES;
- fields : PMYSQL_FIELD;
- field_count : integer;
- procedure ExitNicely(err : integer);
- begin
- WriteLn(mysql_error(db));
- mysql_close(db);
- Halt(err);
- end;
- begin
- db := mysql_init(nil);
- mysql_real_connect(db, nil, PChar(ParamStr(1)), nil, PChar('test'), 0, nil, 0);
- if mysql_errno(db) <> 0
- then ExitNicely(1);
- mysql_query(db, 'DROP TABLE people');
- mysql_query(db, 'CREATE TABLE people (id serial, name varchar(20),age int)');
- mysql_query(db, 'INSERT INTO people (name,age) VALUES (''John'',20), (''Jef'',21)');
- if mysql_query(db, 'SELECT id, name, age FROM people') <> 0
- then ExitNicely(2);
- res := mysql_store_result(db);
- field_count := mysql_field_count(db);
- fields := mysql_fetch_fields(res);
- WriteLn('Field count = ' + IntToStr(field_count));
- WriteLn('Name="' + ((fields + 0)^).name +'"');
- WriteLn('Name="' + ((fields + 1)^).name +'"');
- WriteLn('Name="' + ((fields + 2)^).name +'"');
- mysql_free_result(res);
- mysql_close(db);
- end.
Add Comment
Please, Sign In to add comment