

delphi11中使用FireDAC连接mysql上传字符串后半截乱码
解决方法
连接字符集不要用utf8或urf8mb4,改为gbk就正常了,或者用uniDAC
procedure TForm1.Button2Click(Sender: TObject);
var
q1: TFDQuery;
begin
FDConnection1.Params.DriverID := 'MySQL';
FDConnection1.Params.Add('Server=localhost');
FDConnection1.Params.Add('Port=3306');//默认端口可省略这行
FDConnection1.Params.Database := 'ctcms';
FDConnection1.Params.UserName := 'root';
FDConnection1.Params.Password := 'root';
//FDConnection1.Params.Add('CharacterSet=utf8');
FDConnection1.Params.Add('CharacterSet=gbk');
FDPhysMySQLDriverLink1.VendorLib := '.\..\..\libmysql.dll';
FDQuery1.Connection := FDConnection1;
q1 := TFDQuery.Create(nil);
q1.Connection :=FDConnection1;
try
q1.SQL.Text := 'INSERT INTO ct_txthtml (title, html) VALUES (:title, :html)';
q1.ParamByName('title').Value := '我是中国人';
q1.ParamByName('html').Value := 'html';
q1.ExecSQL; // 执行 SQL 语句插入数据
ShowMessage('数据插入成功!');
except
on E: Exception do
begin
ShowMessage('数据插入失败:' + E.Message);
end;
end;
q1.Free;
end;