Questions tagged [database]
Drupal provides a standard, vendor-agnostic abstraction layer for accessing database servers.
302
questions
26
votes
4answers
16k 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 ...
26
votes
5answers
20k 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 ...
8
votes
4answers
5k 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 ...
9
votes
2answers
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. ...
62
votes
6answers
67k 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 ...
13
votes
5answers
14k 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 ...
69
votes
3answers
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?
5
votes
3answers
28k 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 ...
6
votes
2answers
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 ...
49
votes
7answers
41k 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 ...
52
votes
7answers
48k 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 ...
30
votes
7answers
25k 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 ...
4
votes
1answer
1k 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 ...
41
votes
11answers
27k 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 ...
23
votes
5answers
26k 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 ...
20
votes
2answers
16k 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 ...
17
votes
5answers
17k 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 ...
5
votes
2answers
5k 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
...
2
votes
4answers
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....
37
votes
4answers
26k views
What's the proper use of EntityFieldQuery?
In Drupal 7, the API documentation for node_load_multiple() specifies using the $conditions parameter has been deprecated in favor of using EntityFieldQuery. How does one use the class to generate a ...
13
votes
3answers
14k 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.
14
votes
4answers
286 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?
13
votes
2answers
12k 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 ...
10
votes
2answers
9k 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 ...
7
votes
5answers
7k 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 ...
14
votes
3answers
5k 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', // ...
2
votes
4answers
7k 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',
...
9
votes
2answers
5k views
How to execute stored procedures in drupal?
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 ...
4
votes
3answers
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, ...
3
votes
2answers
941 views
queries with db_select don't respect integers
When I check "SHOW PROCESSLIST" in phpMyAdmin I can see lots of queries where argument-integers are being inserted as strings (with single quotation marks).
I'm wondering if this is due to the way ...
40
votes
3answers
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 ...
18
votes
3answers
23k 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 ...
12
votes
2answers
10k 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 ...
6
votes
1answer
8k 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
...
20
votes
4answers
13k 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' => '...
8
votes
3answers
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......
3
votes
2answers
777 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 ...
4
votes
3answers
4k 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 ...
7
votes
2answers
16k 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/...
5
votes
3answers
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. ...
4
votes
4answers
1k 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('...
4
votes
3answers
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 ...
1
vote
0answers
540 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.
...
23
votes
4answers
12k 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 ...
38
votes
5answers
26k 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', ...
17
votes
3answers
34k 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 ...
28
votes
5answers
36k 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
...
12
votes
3answers
50k views
what is a reasonable value for max_allowed_packet for Drupal 7 with moderate trafficļ¼
I need to know some ball park number for this variable for my drupal 7 site. I recently got a "drupal "PDOException: SQLSTATE[08S01]: Communication link failure: 1153" error. I am a newbie to mysql ...
9
votes
3answers
9k 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 ...
8
votes
2answers
11k views
How can I save arrays of values in the database?
I am trying to save multiple values from a textarea to a database table.
I use the following code, but I feel it is the wrong way.
foreach ($user_emails as $key => $value) {
$...