Ved bruk av mysql.pas, må du inkludere libmysql.dll i samme mappe som programmet.
Denne koden bruker jeg når jeg skal hente nyhetene på hjemmesiden min. Håper du kan finne ut av det
var
sql: TMYSQL;
res: PMYSQL_RES;
row: PMYSQL_ROW;
i: Integer;
username: String;
begin
mysql_connect(@sql, mysql_hostname, mysql_username, mysql_password);
mysql_select_db(@sql, mysql_database);
if mysql_query(@sql, 'SELECT UNIX_TIMESTAMP(datetime) AS datetime, uid, subject, article FROM news ORDER BY id DESC') = 0 then
begin
res := mysql_store_result(@sql);
if res <> nil then
begin
for i := 0 to mysql_num_rows(res) - 1 do
begin
row := mysql_fetch_row(res);
if mysql_query(@sql, PChar(Format('SELECT username FROM user_accounts WHERE id=''%s'' LIMIT 1', [row^[1]]))) = 0 then
username := mysql_fetch_row(mysql_store_result(@sql))^[0];
with ListView1.Items.Add do
begin
Caption := row^[2]; // subject
with SubItems do
begin
Add(DateTimeToStr(UnixToDateTime(StrToInt(row^[0])))); // date & time
Add(username); // username
end;
end;
end;
end;
end;
mysql_close(@sql);
end;
-------------------------------------
I am AGAINST TCPA!!
[
http://www.againsttcpa.com/ ]
-------------------------------------
Mvh
DiZpel
[Redigeret d. 02/02-05 21:20:19 af DiZpel]