使用 Delphi 2010 将 Unicode 字符插入 MySQL
尝试使用 Delphi 2010 和 TADOConnection 将带有 Unicode 字符的值插入 MySQL 数据库,但没有成功。
与 ODBC 连接
Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysrc;Initial Catalog=mydb
SQL 命令:
INSERT INTO myTable (aCol) VALUES('Russian: русский язык')
尝试直接插入它,
TADOConnection.Execute(SQL)
结果在数据库中仅显示为“Russian: ????????? ????”
还尝试了这里建议的方法: http://www.3delite.hu/Object%20Pascal%20Developer%20Resources /delphiunicodemysqltutorial.html <代码>
With TADOQuery do
begin
SQL.Clear;
SQL.Add('INSERT INTO myTable (aCol) VALUES(:p));
Parameters.ParamByName('p').DataType := ftWideString;
Parameters.ParamByName('p').Value := 'Russian: русский язык';
ExecSQL;
end;
仅当我在设计时添加参数时,在代码中进行此操作对我来说根本不起作用,但在数据库中它仍然是相同的结果,并且到处都是问号。
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and TADOConnection with no luck.
Connection with ODBC
Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysrc;Initial Catalog=mydb
The SQL command:
INSERT INTO myTable (aCol) VALUES('Russian: русский язык')
Tried inserting it directly with
TADOConnection.Execute(SQL)
It only ends up in the database as "Russian: ??????? ????"
Also tried the method suggested here:
http://www.3delite.hu/Object%20Pascal%20Developer%20Resources/delphiunicodemysqltutorial.html
With TADOQuery do begin SQL.Clear; SQL.Add('INSERT INTO myTable (aCol) VALUES(:p)); Parameters.ParamByName('p').DataType := ftWideString; Parameters.ParamByName('p').Value := 'Russian: русский язык'; ExecSQL; end;
Making this in code doesn't work at all for me, only if I add parameters in designtime, but then it's still the same result in the database with questionmarks all over.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TADOConnection 似乎不支持 Unicode,至少我无法让它工作。
如果我改为使用 dbExpress TSQLConnection 和 TSQLQuery 插入数据库,它将按预期工作。但我必须使用参数来完成,而不是直接使用 INSERT 命令来完成
It seems TADOConnection doesn't support Unicode, at least I can't get it to work.
If I instead use dbExpress TSQLConnection and TSQLQuery to insert to the database it works as intended. But I must do it with Parameters and not with directly with an INSERT command
我相信这个 PHP 脚本首先执行
SET NAMES utf8
查询I believe this PHP script executes a
SET NAMES utf8
query first