Questions tagged [database]

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

Filter by
Sorted by
Tagged with
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
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
9 votes
4 answers
6k views

PDOException when creating the table: Base table or view not found [closed]

I have Drupal running on MariaDB 5.5.33. When I run update.php (after upgrade to Drupal 7.28 from Drupal 6) I get an error: Failed: PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 ...
Tilia's user avatar
  • 233
9 votes
2 answers
7k views

How do I convert a database from MyISAM to InnoDB?

I am going to convert all the tables of 500MB database from MyISAM to InnoDB to see whether it will improve the overall performance of a busy Drupal 6 site. I am wondering what is the best (i.e. ...
alfish's user avatar
  • 1,947
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
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
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
6 votes
2 answers
7k views

EntityFieldQuery display pager

How do I display pager using EntityFieldQuery for fetch results? I can't find complete example. I am doing simmilar to: Sortable, paged table retrieved using EntityFieldQuery But I miss part to ...
NenadP's user avatar
  • 1,517
5 votes
3 answers
30k views

Solving "MySQL server has gone away", mysql error 2006 [duplicate]

I have a site at hostgator, using their "Business account". It's cheap, and comes with a private SSL cert. HOWEVER, their MySQL settings are such that any db connection goes stale fairly quickly, and ...
Blake Senftner's user avatar
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
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
6 votes
1 answer
2k views

Can I delete leftover field_deleted_* tables?

I have a lot of field_deleted_* tables in the database and neither drush cr or running cron is removing them. Is it okay to just remove them from the database? How can I tell Drupal to remove them ...
Kevin's user avatar
  • 27.8k
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
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
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
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
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
5 votes
5 answers
3k views

Entity Query field condition for Webform submissions

I'm trying to query webform submissions based on a field value. The field is called "ticket_for". Somethings I tried and do not work: ->condition('ticket_for',$adnummer) ->condition('...
Janec Poppeliers's user avatar
5 votes
2 answers
6k views

Using db_query() or db_select() to connect to multiple databases

How can I execute a query that connects to different databases? I have the following query, and I need to rewrite it for Drupal. SELECT a.empid, b.empname FROM db1..empidmaster a, db2..emplist b ...
jacksantho's user avatar
2 votes
4 answers
5k views

Change module's weight - by module or manualy

I am looking for solution how to change particular module's weight in D7. I know that it is possible to do in config tables in database, but I don't know how. Another solution that I found in Drupal....
Benas Plentas'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 ...
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
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
9 votes
2 answers
10k views

How to define and use an external database connection in a custom module

I'm developing a module that will rely heavily on external database queries. Is there a best practice for defining and using an external database connection throughout a module? This page tells me ...
Whiskey's user avatar
  • 1,378
9 votes
2 answers
5k views

How do I execute stored procedures? [closed]

I have a website which does lot of work on financial data. It involves operations on large volumes of data most of the time. Hence I find it useful to do those operations in MySQL stored procedures. I ...
Mahesh Bhat's user avatar
7 votes
5 answers
8k views

Changing an inner join to a left join in views 3.3?

Using views 3.3, I have a view in Drupal 7 where I am showing two content types. I have a filter criteria based on the value of a field that is attached only to one of the content types. So long as I ...
user1359's user avatar
  • 3,909
4 votes
3 answers
6k views

How to sort on different columns in the same view?

I'm trying to build a Glossary View in Drupal 8. Let's say I have 3 content types: Person, Article, Event. I want sort by title ASC for Article and Event, but sort by Last Name for Person. So that ...
Greg's user avatar
  • 842
4 votes
3 answers
1k views

PHP in database: bad practice but

Lots of times here I've been told that using views custom php fields, filters or others is a bad practice, because putting php in the sql is dangerous. My question is, if you only call to a function, ...
Gregory Kapustin's user avatar
2 votes
4 answers
9k views

Inserting the value from Datetime field form

I have a form where the user can input datetime and then I want to store it in the database. Here's my schema : 'start' => array( 'type' => 'varchar', 'mysql_type' => 'datetime', ...
bravely23's user avatar
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
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
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
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
11 votes
4 answers
14k views

How do I change a field type?

I have a content type with a field_maps whose type is Text (plain, long). I needed to change it to Text (plain). So I've done this SQL statement: ALTER TABLE node__field_maps MODIFY field_maps_value ...
Hefi's user avatar
  • 189
11 votes
2 answers
11k views

hook_schema is not creating database table

The following function is contained in process_login.install as part of a custom module called process_login. The module works if I manually created the database table, but naturally I would like the ...
user8109's user avatar
  • 211
8 votes
4 answers
5k views

How to add a database index to a base field

Goal: Add a database index to a 'created' field. Given: There is a custom entity with a base field created. The field is stored the entity table. Field source code of the created field: $fields['...
milkovsky's user avatar
  • 5,334
8 votes
3 answers
16k views

General error: 2006 MySQL server has gone away [closed]

This is the error I am suddenly getting. Additional uncaught exception thrown while handling exception. Original PDOException: SQLSTATE[70100]: Unknown error: 1317 Query execution was interrupted......
dbj44's user avatar
  • 4,744
7 votes
2 answers
18k views

Problem with PDO MySQL

For the last couple of days I've been getting the following error: Fatal error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY' in /home/mydomain/public_html/drupal/includes/database/mysql/...
brunn's user avatar
  • 257
6 votes
1 answer
9k views

PDOException: SQLSTATE[HY000] [2002] No such file or directory in _registry_check_code()

Drush is running on MAMP, PHP 5.6.6. Inside /Volumes/Doxy/htdocs/omegadoen/sites/all/themes/omega I run: drush omega-wizard I get: Additional uncaught exception thrown while handling ...
Bi Devi's user avatar
  • 81
5 votes
3 answers
1k views

Sync +- 70 000 records from CSV into drupal

I have a CSV file with approx. 70.000 records that I want to import into Drupal 7. Once this is done the client will provide a new CSV file on a daily base that has to sync the updated rows to Drupal. ...
Jenzzz's user avatar
  • 71
4 votes
3 answers
1k views

EntityFieldQuery doesn't work correctly in hook_cron

I am programming a new module in my Drupal 7 project. in my module hook_cron is override. in my hook_cron function, I want to select a node type with specific filter for a cck field. I am using ...
Mehrdad201's user avatar
  • 1,312
3 votes
2 answers
837 views

How to create complex conditional clauses / queries?

I've been reading the documentatoin on conditional clauses and also studied the api description for db_and() and db_or() but I fail to create a $query with 3 ->conditions: select all between 0 and ...
q9f's user avatar
  • 537
1 vote
0 answers
545 views

How to fix - PDOException: SQLSTATE[42S22] [duplicate]

I cannot seem to get rid of this error after numerous updates, anyone got any ideas/advice how to fix it as my Admin Modules doesn't want to load at all. I'm running D7.26 on this project. Thanks. ...
Paul B's user avatar
  • 579
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
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
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
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
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

1
2 3 4 5
7