简体   繁体   English

如何在MyQuery(Delphi)中将数据插入MySQL表

[英]How to insert data into a MySQL table in MyQuery (Delphi)

I am doing mysql connection by establishing a user-registration application. 我正在通过建立用户注册应用程序来进行mysql连接。 I use Delphi 7. Myquery (MySQL Access Set) have a problem with adding user information. 我使用Delphi7。Myquery (MySQL访问集)在添加用户信息时遇到问题。

MyQuery1.SQL.Clear;
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (nick) VALUES ('+QuotedStr(DBEdit1.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (mail) VALUES ('+QuotedStr(DBEdit2.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (site) VALUES ('+QuotedStr(DBEdit3.text)+')');
MyQuery1.SQLInsert.Add('INSERT INTO uyeler (pass) VALUES ('+QuotedStr(DBEdit4.text)+')');
MyQuery1.CachedUpdates:=True;
MyQuery1.Open;

Error message: MyQuery1: No SQL statement provided. 错误消息: MyQuery1:未提供SQL语句。

Note: uyeler: members table. 注意: uyeler:成员表。

This message is raised because you are not filling the SQL property, instead you are using the SQLInsert which is a template for query statements. 出现此消息是因为您没有填充SQL属性,而是使用了SQLInsert这是查询语句的模板)。

Some additional tips 一些其他技巧

  1. You must use the Execute method, The Open method is for SELECT sentences. 您必须使用Execute方法, Open方法用于SELECT语句。
  2. use a single insert sentence like 使用单个插入语句,例如

    INSERT INTO uyeler (nick,mail,site,pass) VALUES ('','','','') 插入uyeler(昵称,邮件,站点,密码)值('','','','')

  3. Try using parameters, instead of passing the string values directly, in this way you will avoid sql injection attacks and you will increase the performance. 尝试使用参数,而不是直接传递字符串值,这样可以避免sql注入攻击,并可以提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM