Questions tagged [database]

Drupal provides a standard, vendor-agnostic abstraction layer for accessing database servers.

Filter by
Sorted by
Tagged with
71 votes
3 answers
12k views

Given that db_select is much slower than db_query, why would I want to use it?

For the background on this, please see http://drupal.org/node/1067802. Given all that, what situations exists where I might want to use db_select(), or should I be relying solely on db_query?
Chris Cohen's user avatar
  • 1,945
64 votes
7 answers
73k views

Print the query which is built using db_select()

I want to print the query which is built using db_select() in a programmatical way. Is there any API function provided by Drupal Abstraction Layer? It is similar to query output in Views, but I want ...
Sithu's user avatar
  • 4,953
53 votes
8 answers
51k views

"OR" condition in db_select()

I am studying the new database layer, and I am glad it is changed to an OOP layer. I need to implement a query with db_select(). I found I can add a WHERE statement with $query->condition(), but by ...
Yuseferi's user avatar
  • 22k
50 votes
7 answers
45k views

How to change the length of field settings?

I have set once to a website a lenght limit to a field. And now the client wants to put more characters to that field. I cannot change the maximum size from Drupal because I get the following error ...
radu c's user avatar
  • 4,350
44 votes
11 answers
30k views

Which tables are safe to clear?

I have inherited a client site that has an extremely large database for no reason. There is a moderate amount of content and very little enabled modules. However, the database is too large for moving ...
Nigel Waters's user avatar
  • 1,024
39 votes
3 answers
7k views

How do I merge changes from a development copy of the site to the live site without losing new content?

What is the best procedure for merging work done on a development copy of a site to the live production copy? Often times there has been a lot of new content added to the site since development ...
Chaulky's user avatar
  • 6,453
38 votes
5 answers
28k views

Using IN clause in db_query

I can't figure out how to add an IN clause in my query, using placeholders. I'd want it to be something like: $nids = array(1, 2, 3); $result = db_query('SELECT * FROM {node} WHERE nid IN :nids', ...
Olof Johansson's user avatar
37 votes
4 answers
28k views

What's the proper way to use EntityFieldQuery?

In Drupal 7, the API documentation for node_load_multiple() says that using the $conditions parameter has been deprecated in favor of using EntityFieldQuery. In which way should EntityFieldQuery be ...
31 votes
7 answers
27k views

Excluding empty(Null) fields when using EntityFieldQuery query condition

Is it possible to select all of the entities who's xyz field is empty? I tried soemthing like this: ->fieldCondition('field_name', 'value', NULL, 'IS NOT NULL'); However, this doesn't seem to ...
David Barratt's user avatar
29 votes
5 answers
40k views

How do I use "NOT IN" in a query?

What is the proper way to write a query containing 'NOT IN' using a condition statement? My query is the following one: SELECT DISTINCT nid FROM node WHERE language NOT IN (SELECT language ...
JurgenR's user avatar
  • 2,163
29 votes
4 answers
20k views

Database general error: 2006 MySQL server has gone away

Recently I started getting an error every time I try and add a content no matter what type. This is the error that shows up in the browser: Additional uncaught exception thrown while handling ...
Mike2012's user avatar
  • 1,761
27 votes
8 answers
87k views

How do I get only one result using db_query()

I am transitioning from 'old school' PHP MySQL methods of using mysql_fetch_array(), etc. and I am trying to be more Drupally by using the Database API in my modules. I simply want to return and ...
blue928's user avatar
  • 3,804
27 votes
5 answers
21k views

Using OR with EntityFieldQuery

I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries. An example would get to all entities ...
googletorp's user avatar
  • 35.4k
24 votes
10 answers
34k views

How do I change the machine name of a field once it's been created

I spaced out while typing the field name an now the machine name is not what I wanted it to be. I know it's just an annoyance. but I'm wondering if there is some way to alter the machine name of a ...
user379468's user avatar
  • 2,520
24 votes
4 answers
13k views

Custom query in Views?

At some point I found the need to modify an SQL query generated by Views, in the end I overrode views_pre_execute and changed the query for that specific view. This feels like an ugly hack to me and ...
Mad Scientist's user avatar
23 votes
5 answers
31k views

Get the actual query executed by a view

I need to find out the SQL query that is executed by a certain query. Views module can show the SQL when configuring the view but apparently the query is not the actual query that gets run in all ...
jjei's user avatar
  • 683
22 votes
4 answers
47k views

Perform a query with an entity field condition with multiple values

I have a content type that has a entity reference field that allows users to add multiple taxonomy terms in that field. I'm attempting to perform queries that grab nodes that have a specific set of ...
Amy's user avatar
  • 5,662
22 votes
5 answers
13k views

reseting the hook_update_n status of a module

I'm extending a module I've previously written and it needs some schema changes which I implement in hook_update_N. I've updated the module's version from 7.x-1.0 to 7.x-1.1 and implemented the ...
cherouvim's user avatar
  • 1,937
20 votes
2 answers
17k views

EntityFieldQuery INNER JOIN

I'd like to run a query using the EntityFieldQuery object. I need value from both the node and node_access table therefore I'd need to use INNER JOIN. From the d.o documentation I can't figure out how ...
Allan Thomas's user avatar
20 votes
4 answers
14k views

How do you make sortable tables with a pager with data from a custom table?

For Drupal 6 you could do something like this: $header = array( array('data' => t('Order id'), 'field' => 'order_id'), ... array('data' => t('Transaction time'), 'field' => '...
googletorp's user avatar
  • 35.4k
19 votes
1 answer
15k views

Joins and looking for NULL values

I'm using the flag module to let users mark their questions as solved, similar to how it works on this site. I therefore want to let users filter posts to show only unsolved questions. Additionally, ...
maxedison's user avatar
  • 1,231
19 votes
3 answers
26k views

How to get rid of Deadlocks and Lock time out type issues?

I read multiple blogs, tried to google, it but didn't find any satisfaction from any solution. I have the following issues : PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found ...
Sumit Madan's user avatar
  • 3,473
19 votes
4 answers
6k views

How to get core to leverage a MySQL master/slave configuration?

I read this question MySQL master/slave replication not working and its answer: Using slave databases is barely implemented in Drupal core. If you are developing your own modules then calls to ...
tostinni's user avatar
  • 9,103
19 votes
2 answers
12k views

Using LIKE in db_query in D7

I have a query like this in Drupal 6: $sql = 'SELECT sid, score FROM search_index WHERE word LIKE "%%%s%%"'; $result = db_query($sql,$search_term); And it worked fine, but now I'm upgrading to ...
Coomie's user avatar
  • 1,209
18 votes
5 answers
27k views

Is it possible to restore a deleted node?

While revisions are kept and it is easy to get back to a previous revision of a node, I was wondering if it is possible to restore a node that has really been deleted by a user?
Palmin's user avatar
  • 383
18 votes
5 answers
18k views

How can I setup multiple database connections?

Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.
Mudassar Ali's user avatar
  • 1,099
18 votes
5 answers
19k views

How I can delete all node/field revisions?

I have a drupal 7 sites, where it keeps node and field revisions. I keep revisions for the case where by mistake a new faulty version is saved and I want to revert back. But, now I want to clean and ...
john's user avatar
  • 1,601
18 votes
1 answer
197 views

Can a database be tested to see if it is inconsistent?

We all know that Drupal doesn't really support the concept of foreign keys in the database, and likely never will1. We also know that it is possible for modules to not do the right thing, or that ...
mpdonadio's user avatar
  • 38.1k
17 votes
1 answer
5k views

How to expose non Drupal tables in Views?

I wonder what is the best way to allow the Views module to access external tables not in Drupal? I tried the Data module, but it doesn't allow for a datetime datatype.
mcercado's user avatar
  • 171
16 votes
2 answers
25k views

How to publish unpublished nodes programmatically

I have some unpublished nodes, for which I have their node IDs. How can I programmatically publish them? Is it correct to achieve it in custom module using a query like the following? db_query("...
jim gaslingson's user avatar
16 votes
6 answers
38k views

How do you build up a LIKE condition in a db_select() query?

How do you build up a LIKE condition in a db_select() query? I know how to do this with a db_query() API call, but is there a special syntax / method for doing this with db_select()?
Anil Sagar's user avatar
  • 12.2k
16 votes
2 answers
4k views

Whats faster db_query, db_select, or EntityFieldQuery

So I'm trying to find out what is faster db_query, db_select, or EntityFieldQuery. Currently I'm using EntityFieldQuery. I'm grabbing about 1600 node entries. I realize this can be taxing on the ...
Jorge Calderon's user avatar
16 votes
2 answers
27k views

How do I create table in custom module

In Drupal 7 we used to use hook_schema() in the .install file to create a table. I believe that, in Drupal 8, you can do that as well, but I was under the impression that you should create .yml files ...
albertski's user avatar
  • 3,447
15 votes
7 answers
51k views

Adding a new user directly in database

I've been given the files to a Drupal site so I can create a new theme. I haven't, however, been given the Drupal admin user/password date so I can't sign in to the admin area. Is there a way I can ...
Jane's user avatar
  • 1,805
15 votes
2 answers
41k views

Select fields from two tables using db_select()

I am using db_select() and I don't understand the syntax of the fields() method. I'm using a join() to join another table. So for tables t and n, I want to do something like SELECT t.tid, t.field1, t....
user1359's user avatar
  • 3,909
15 votes
4 answers
12k views

Looking for database insert example

According to db_insert manual page this function is deprecated and it is better to use Drupal 8 database connection to perform insert. Deprecated as of Drupal 8.0.x, will be removed in Drupal ...
Mohammad Ali Akbari's user avatar
15 votes
1 answer
10k views

How get empty record on date field with entityQuery?

I am on a custom entity with custom fields and i try to get all empty record on date field : Field was create with CCK, so the field storage has a table. $query = \Drupal::entityQuery('test_entity'...
Kevin's user avatar
  • 2,558
15 votes
1 answer
3k views

is db_insert secure?

I'm using the Drupal 7 method db_insert, to insert data into a custom table in the Drupal database. I've read that this is the prefered way, however I've walked through the code and doco and I can't ...
user avatar
15 votes
2 answers
2k views

How to teach PhpStorm to recognise drupal {table} SQL syntax?

I'm dealing with some really old drupal project full of SQL queries. PhpStorm's understanding of SQL is very handy however I have problems with drupalism like {table_name}. IDE complains that <...
SiliconMind's user avatar
  • 3,181
14 votes
1 answer
17k views

How to write a Drupal 7 query with "count" and "having" properties?

I am unable to make the following query work in drupal7 standards..Can anyone help me with this? Its little urgent... SELECT n.nid AS nid, n.title AS title, count(n.title) AS ncount FROM node n ...
Jons's user avatar
  • 237
14 votes
3 answers
8k views

NoSQL vs Other SQL Drupal Setups

What are the advantages of running NoSQL (ex MongoDB) over MySQL, PostGRE SQL or MSSQL in Drupal? Are the advantages gained from simply using the storage or does some Drupal configuration need to ...
Kevin's user avatar
  • 27.8k
14 votes
4 answers
296 views

Can any of the cache_* be emptied safely?

Sometimes when moving the database it can be too large. Can any of the "cache_" prefixed tables be emptied without causing problems?
WestieUK's user avatar
  • 3,838
14 votes
3 answers
7k views

Is it always bad to pass a variable through t()?

I have a little helper function for my hook_schema: function _bbcmap_schema_asr_field($description) { return array( 'type' => 'int', 'unsigned' => TRUE, 'size' => 'small', // ...
Andy's user avatar
  • 4,996
14 votes
2 answers
16k views

Fatal error: Call to undefined function cache_get() [closed]

I am getting the following error on the server Fatal error: Call to undefined function cache_get() in includes/module.inc on line 665 Drush command terminated abnormally due to an unrecoverable error....
Dinesh Kumar Sarangapani's user avatar
14 votes
2 answers
13k views

How to create a table during the module installation

I'm trying to create a module for Drupal 7 and I need to create 3 tables and populate it. But first i need to create it. In the file mymodule.install I have got function mymodule_install() { } ...
Tyler Durden's user avatar
  • 2,316
14 votes
2 answers
14k views

How to implement a mysql date or datetime field correctly in hook_schema()?

I have written a mymodule.install file which contains a schema definition to create a table in my database. This table contains two data fields. Theese fields will be populated by the users when they ...
Marco's user avatar
  • 157
14 votes
3 answers
8k views

Is it safe to truncate a field revision table?

I noticed D7 creates a field_revision table for every field, and duplicates the content from its field table counterpart even if one has revisions turned off. I have a big text table and it is taking ...
giorgio79's user avatar
  • 4,621
13 votes
3 answers
14k views

What does vid mean

I have designed a view and I see this query in the preview section: SELECT node.nid AS nid, node_data_field_crm_history_brokerid.field_crm_history_brokerid_value AS ...
user avatar
13 votes
6 answers
17k views

Cache Form table size is enormous

Cache table's size had increased to 10+ GB last month, and I had fixed it temporarily by truncating it. Last time I checked it was around 1GB. So in couple of months it will hit 10GB again. How should ...
GoodSp33d's user avatar
  • 2,304
13 votes
6 answers
9k views

Does drush up do a database backup/dump?

Does running drush up run a database backup? From testing, it looks like it doesn't. Should I be doing a separate database backup before I run drush up to update?
user1359's user avatar
  • 3,909

1
2 3 4 5
63