How to create a query in Drupal 8

前端 未结 3 1888
情话喂你
情话喂你 2021-02-13 21:18

I am used to using db_select in drupal 7 but now it\'s deprecated in drupal 8

So, If I need to create a query to list all users from users_field_data table,

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 21:40

    db_select, db_insert, db_update, etc... were deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0.

    Instead get a database connection injected into your service from the container and call select() on it. For example, $injected_database->select($table, $alias, $options);.

    eg:

    $db = \Drupal::database();
    
    $data = $db->select('table_name','t')->fields('t')->execute();
    
    $db->insert();
    
    $db->update();
    

提交回复
热议问题