testdb3.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. program testdb3;
  2. uses
  3. mysql3;
  4. Const
  5. DataBase : Pchar = 'testdb';
  6. Query : Pchar = 'Select * from FPdev';
  7. var
  8. count,num : longint;
  9. code : integer;
  10. sock : PMYSQL;
  11. qmysql : TMYSQL;
  12. qbuf : string [160];
  13. rowbuf : TMYSQL_ROW;
  14. dummy : string;
  15. recbuf : PMYSQL_RES;
  16. begin
  17. if paramcount=1 then
  18. begin
  19. Dummy:=Paramstr(1)+#0;
  20. DataBase:=@Dummy[1];
  21. end;
  22. Write ('Connecting to MySQL...');
  23. sock := mysql_connect(PMysql(@qmysql),nil,'michael','geen');
  24. if sock=Nil then
  25. begin
  26. Writeln (stderr,'Couldn''t connect to MySQL.');
  27. Writeln (stderr,mysql_error(@qmysql));
  28. halt(1);
  29. end;
  30. Writeln ('Done.');
  31. Writeln ('Connection data:');
  32. {$ifdef Unix}
  33. writeln ('Mysql_port : ',mysql_port);
  34. writeln ('Mysql_unix_port : ',mysql_unix_port);
  35. {$endif}
  36. writeln ('Host info : ',mysql_get_host_info(sock));
  37. writeln ('Server info : ',mysql_stat(sock));
  38. writeln ('Client info : ',mysql_get_client_info);
  39. Writeln ('Selecting Database ',DataBase,'...');
  40. if mysql_select_db(sock,DataBase) < 0 then
  41. begin
  42. Writeln (stderr,'Couldn''t select database ',Database);
  43. Writeln (stderr,mysql_error(sock));
  44. halt (1);
  45. end;
  46. writeln ('Executing query : ',Query,'...');
  47. if (mysql_query(sock,Query) < 0) then
  48. begin
  49. Writeln (stderr,'Query failed ');
  50. writeln (stderr,mysql_error(sock));
  51. Halt(1);
  52. end;
  53. recbuf := mysql_store_result(sock);
  54. if RecBuf=Nil then
  55. begin
  56. Writeln ('Query returned nil result.');
  57. mysql_close(sock);
  58. halt (1);
  59. end;
  60. Writeln ('Number of records returned : ',mysql_num_rows (recbuf));
  61. Writeln ('Number of fields per record : ',mysql_num_fields(recbuf));
  62. rowbuf := mysql_fetch_row(recbuf);
  63. while (rowbuf <>nil) do
  64. begin
  65. Write ('(Id: ', rowbuf[0]);
  66. Write (', Name: ', rowbuf[1]);
  67. Writeln(', Email : ', rowbuf[2],')');
  68. rowbuf := mysql_fetch_row(recbuf);
  69. end;
  70. Writeln ('Freeing memory occupied by result set...');
  71. mysql_free_result (recbuf);
  72. Writeln ('Closing connection with MySQL.');
  73. mysql_close(sock);
  74. halt(0);
  75. end.
  76. $Log$
  77. Revision 1.1 2004-09-30 19:34:47 michael
  78. + Split everything in version 3 and version 4
  79. Revision 1.4 2004/09/28 19:08:09 michael
  80. + Some compatibility issues fixed
  81. Revision 1.3 2002/09/07 15:42:53 peter
  82. * old logs removed and tabs fixed
  83. Revision 1.2 2002/05/31 11:54:33 marco
  84. * Renamefest for 1.0, many 1.1.x spots patched also.
  85. Revision 1.1 2002/01/29 17:54:54 peter
  86. * splitted to base and extra
  87. }