首页 文章

使用Delphi进行数据库连接和选择(FIREMONKEY - iOS)

提问于
浏览
2

我有一个数据库,想要选择 DELPHI and FIREMONKEY CROSSOVER 的条目 . 但我从来没有在DELPHI上使用过SQL . 我无法弄清楚如何使用DELPHI连接到数据库 . 我不想要一个装满组件的手 . 它应该是一个简单的连接,就像PHP一样 .

我使用XAMPP - mySQL . 假设我们有一个数据库,"db_x",带有表格"users",在该表中有以下条目: name: Michael; surname: Schneider; age: 22 .

数据库位于“localhost”或其他位置,登录名为“root”,密码为“rootpw” . 要在PHP中连接到数据库,我们使用:

mysql_connect("localhost","root","rootpw") or die ("Connection Error");
mysql_select_db("db_x") or die ("Error DB");

现在我想从名为“ Michael ”的用户那里得到 surname

$query= mysql_query("SELECT surname FROM users WHERE name = 'Michael'")  
or die  
(mysql_error());   

while($zeile = mysql_fetch_array( $query )) 
{ 
    echo $zeile['surname']."<br>";
}

Now this is about PHP, but what about DELPHI? 我有相同的数据库,想要显示用户的姓氏,但我甚至不知道如何连接DELPHI( and it should also support Firemonkey and work on iOS ) .

对不起我做的语法错误 .

感谢所有来自德国的回答和问候 .

2 回答

  • 1

    For the sake of completeness on this dinosaur.

    我没有找到我当时使用的功能,但它与此类似:

    http := TIdHttp.Create(nil);
    http.HandleRedirects := true;
    http.ReadTimeout := 6000;
    jsonToSend := TStringList.create;
    jsonToSend.Text := 'json={"food":"Pizza"}';
    Memo1.Lines.Text := http.Post('http://www.mypage.com/mydata.php', jsonToSend);
    jsonToSend.free;
    http.free;
    

    和简单的mysql和json编码在mydata.php中

  • 0

    Delphi中有各种方法,在这个例子中我有以下内容:

    我在表单上有一个TSQLConnection对象(但这可以在代码中创建) . 我在组件上设置了数据库连接和数据库设置 .

    然后,在代码中......

    //variables
    var Q: TSQLQuery;
    
    //in function
    Q := TSQLQuery.Create(nil);
    try
      Q.SQLConnection := myConnectionObjectOnForm;
      Q.SQL.Text := "SELECT some stuff from TABLE";
      Q.Active := true;
    
      if not Q.Eof then
        //Do stuff eg
        result := Q.Fields[0].AsString;  //or reference FieldByName
    
      Q.Close;
    finally
      Q.Free;
    end;
    

    TSQLQuery和TSQLDataSet最常用于数据检索

相关问题