Runs a basic query in the active database.
User-supplied arguments to the query should be passed in as separate parameters so that they can be properly escaped to avoid SQL injection attacks.
Parameters
$query: A string containing an SQL query.
...: A variable number of arguments which are substituted into the query using printf() syntax. Instead of a variable number of query arguments, you may also pass a single array containing the query arguments.
Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose in '') and %%.
NOTE: using this syntax will cast NULL and FALSE values to decimal 0, and TRUE values to decimal 1.
Return value
A database query result resource, or FALSE if the query was not executed correctly.
Related topics
- Database abstraction layer
- Allow the use of different database servers using the same code base.
▾ 418 functions call db_query()
- actions_delete in includes/
actions.inc - Delete a single action from the database.
- actions_do in includes/
actions.inc - Perform a given list of actions by executing their callback functions.
- actions_function_lookup in includes/
actions.inc - Given an md5 hash of a function name, return the function name.
- actions_get_all_actions in includes/
actions.inc - Retrieves all action instances from the database.
- actions_load in includes/
actions.inc - Retrieve a single action from the database.
- actions_save in includes/
actions.inc - Save an action and its associated user-supplied parameter values to the database.
- actions_synchronize in includes/
actions.inc - Synchronize actions that are provided by modules.
- aggregator_block in modules/
aggregator/ aggregator.module - Implementation of hook_block().
- aggregator_categorize_items in modules/
aggregator/ aggregator.pages.inc - Form builder; build the page list form.
- aggregator_categorize_items_submit in modules/
aggregator/ aggregator.pages.inc - Process aggregator_categorize_items form submissions.
- aggregator_category_load in modules/
aggregator/ aggregator.module - Load an aggregator category.
- aggregator_cron in modules/
aggregator/ aggregator.module - Implementation of hook_cron().
- aggregator_feed_items_load in modules/
aggregator/ aggregator.pages.inc - Load feed items by passing a SQL query.
- aggregator_feed_load in modules/
aggregator/ aggregator.module - Load an aggregator feed.
- aggregator_form_category_validate in modules/
aggregator/ aggregator.admin.inc - Validate aggregator_form_feed form submissions.
- aggregator_form_feed in modules/
aggregator/ aggregator.admin.inc - Form builder; Generate a form to add/edit feed sources.
- aggregator_form_feed_validate in modules/
aggregator/ aggregator.admin.inc - Validate aggregator_form_feed form submissions.
- aggregator_page_categories in modules/
aggregator/ aggregator.pages.inc - Menu callback; displays all the categories used by the aggregator.
- aggregator_page_opml in modules/
aggregator/ aggregator.pages.inc - Menu callback; generates an OPML representation of all feeds.
- aggregator_page_rss in modules/
aggregator/ aggregator.pages.inc - Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
- aggregator_page_sources in modules/
aggregator/ aggregator.pages.inc - Menu callback; displays all the feeds used by the aggregator.
- aggregator_parse_feed in modules/
aggregator/ aggregator.module - Parse a feed and store its items.
- aggregator_refresh in modules/
aggregator/ aggregator.module - Checks a news feed for new items.
- aggregator_remove in modules/
aggregator/ aggregator.module - Removes all items from a feed.
- aggregator_save_category in modules/
aggregator/ aggregator.module - Add/edit/delete aggregator categories.
- aggregator_save_feed in modules/
aggregator/ aggregator.module - Add/edit/delete an aggregator feed.
- aggregator_save_item in modules/
aggregator/ aggregator.module - Add/edit/delete an aggregator item.
- aggregator_view in modules/
aggregator/ aggregator.admin.inc - Displays the aggregator administration page.
- batch_process in includes/
form.inc - Processes the batch.
- block_add_block_form_submit in modules/
block/ block.admin.inc - Save the new custom block.
- block_add_block_form_validate in modules/
block/ block.admin.inc - block_admin_configure in modules/
block/ block.admin.inc - Menu callback; displays the block configuration form.
- block_admin_configure_submit in modules/
block/ block.admin.inc - block_admin_configure_validate in modules/
block/ block.admin.inc - block_admin_display_form_submit in modules/
block/ block.admin.inc - Process main blocks administration form submission.
- block_block in modules/
block/ block.module - Implementation of hook_block().
- block_box_delete_submit in modules/
block/ block.admin.inc - Deletion of custom blocks.
- block_box_get in modules/
block/ block.module - Returns information from database about a user-created (custom) block.
- block_box_save in modules/
block/ block.module - Saves a user-created block in the database.
- block_flush_caches in modules/
block/ block.module - Implementation of hook_flush_caches().
- block_list in modules/
block/ block.module - Return all blocks in the specified region for the current user.
- block_user in modules/
block/ block.module - Implementation of hook_user().
- blogapi_mt_validate_terms in modules/
blogapi/ blogapi.module - Blogging API helper - find allowed taxonomy terms for a node type.
- blog_form in modules/
blog/ blog.module - Implementation of hook_form().
- book_block in modules/
book/ book.module - Implementation of hook_block().
- book_get_books in modules/
book/ book.module - Returns an array of all books.
- book_link_load in modules/
book/ book.module - Like menu_link_load(), but adds additional data from the {book} table.
- book_menu_subtree_data in modules/
book/ book.module - Get the data representing a subtree of the book hierarchy.
- book_nodeapi in modules/
book/ book.module - Implementation of hook_nodeapi().
- book_remove_form_submit in modules/
book/ book.pages.inc - Confirm form submit function to remove a node from the book.
- book_uninstall in modules/
book/ book.install - Implementation of hook_uninstall().
- book_update_6000 in modules/
book/ book.install - Drupal 5.x to 6.x update.
- book_update_bid in modules/
book/ book.module - Update the bid for a page and its children when it is moved to a new book.
- cache_clear_all in includes/
cache.inc - Expire data from the cache. If called without arguments, expirable entries will be cleared from the cache_page and cache_block tables.
- cache_get in includes/
cache.inc - Return data from the persistent cache. Data may be stored as either plain text or as serialized data. cache_get will automatically return unserialized objects and arrays.
- cache_set in includes/
cache.inc - Store data in the persistent cache.
- color_update_6001 in modules/
color/ color.install - Warn site administrator if unsafe CSS color codes are found in the database.
- comment_admin_overview_submit in modules/
comment/ comment.admin.inc - Process comment_admin_overview form submissions.
- comment_delete in modules/
comment/ comment.admin.inc - Menu callback; delete a comment.
- comment_edit in modules/
comment/ comment.pages.inc - Form builder; generate a comment editing form.
- comment_enable in modules/
comment/ comment.install - Implementation of hook_enable().
- comment_form_add_preview in modules/
comment/ comment.module - Form builder; Generate and validate a comment preview form.
- comment_multiple_delete_confirm in modules/
comment/ comment.admin.inc - List the selected comments and verify that the admin really wants to delete them.
- comment_new_page_count in modules/
comment/ comment.module - Calculate page number for first new comment.
- comment_nodeapi in modules/
comment/ comment.module - Implementation of hook_nodeapi().
- comment_num_all in modules/
comment/ comment.module - Get comment count for a node.
- comment_num_new in modules/
comment/ comment.module - Get number of new comments for current user and specified node.
- comment_num_replies in modules/
comment/ comment.module - Get replies count for a comment.
- comment_publish_action in modules/
comment/ comment.module - Action to publish a comment.
- comment_render in modules/
comment/ comment.module - Renders comment(s).
- comment_reply in modules/
comment/ comment.pages.inc - This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
- comment_save in modules/
comment/ comment.module - Accepts a submission of new or changed comment content.
- comment_unpublish_action in modules/
comment/ comment.module - Action to unpublish a comment.
- comment_unpublish_by_keyword_action in modules/
comment/ comment.module - Action to unpublish a comment if it contains a certain string.
- comment_update_1 in modules/
comment/ comment.install - Changed node_comment_statistics to use node->changed to avoid future timestamps.
- comment_user in modules/
comment/ comment.module - Implementation of hook_user().
- comment_validate in modules/
comment/ comment.module - Validate comment data.
- contact_admin_categories in modules/
contact/ contact.admin.inc - Categories/list tab.
- contact_admin_delete_submit in modules/
contact/ contact.admin.inc - Process category delete form submission.
- contact_admin_edit_submit in modules/
contact/ contact.admin.inc - Process the contact category edit page form submission.
- contact_load in modules/
contact/ contact.module - Load the data for a single contact category.
- contact_mail_page in modules/
contact/ contact.pages.inc - dblog_cron in modules/
dblog/ dblog.module - Implementation of hook_cron().
- dblog_event in modules/
dblog/ dblog.admin.inc - Menu callback; displays details about a log message.
- dblog_user in modules/
dblog/ dblog.module - Implementation of hook_user().
- dblog_watchdog in modules/
dblog/ dblog.module - Implementation of hook_watchdog().
- db_add_field in includes/
database.mysql-common.inc - Add a new field to a table.
- db_add_field in includes/
database.pgsql.inc - Add a new field to a table.
- db_check_setup in includes/
database.pgsql.inc - Verify if the database is set up correctly.
- db_column_exists in includes/
database.mysqli.inc - Check if a column exists in the given table.
- db_column_exists in includes/
database.pgsql.inc - Check if a column exists in the given table.
- db_column_exists in includes/
database.mysql.inc - Check if a column exists in the given table.
- db_last_insert_id in includes/
database.mysql-common.inc - Returns the last insert id.
- db_last_insert_id in includes/
database.pgsql.inc - Returns the last insert id. This function is thread safe.
- db_lock_table in includes/
database.mysqli.inc - Lock a table.
- db_lock_table in includes/
database.pgsql.inc - Lock a table. This function automatically starts a transaction.
- db_lock_table in includes/
database.mysql.inc - Lock a table.
- db_table_exists in includes/
database.mysqli.inc - Check if a table exists.
- db_table_exists in includes/
database.pgsql.inc - Check if a table exists.
- db_table_exists in includes/
database.mysql.inc - Check if a table exists.
- db_unlock_tables in includes/
database.mysqli.inc - Unlock all locked tables.
- db_unlock_tables in includes/
database.pgsql.inc - Unlock all locked tables. This function automatically commits a transaction.
- db_unlock_tables in includes/
database.mysql.inc - Unlock all locked tables.
- db_version in includes/
database.pgsql.inc - Returns the version of the database server currently in use.
- drupal_get_filename in includes/
bootstrap.inc - Returns and optionally sets the filename for a system item (module, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists.
- drupal_get_installed_schema_version in includes/
install.inc - Returns the currently installed schema version for a module.
- drupal_install_system in includes/
install.inc - Callback to install the system module.
- drupal_lookup_path in includes/
path.inc - Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
- drupal_set_installed_schema_version in includes/
install.inc - Update the installed version information for a module.
- drupal_uninstall_module in includes/
install.inc - Calls the uninstall function and updates the system table for a given module.
- drupal_write_record in includes/
common.inc - Save a record to the database based upon the schema.
- file_set_status in includes/
file.inc - Set the status of a file.
- file_space_used in includes/
file.inc - Determine total disk space used by a single user or the whole filesystem.
- filter_admin_delete in modules/
filter/ filter.admin.inc - Menu callback; confirm deletion of a format.
- filter_admin_delete_submit in modules/
filter/ filter.admin.inc - Process filter delete form submission.
- filter_admin_format_form_submit in modules/
filter/ filter.admin.inc - Process filter format form submissions.
- filter_admin_format_form_validate in modules/
filter/ filter.admin.inc - Validate filter format form submissions.
- filter_admin_order_submit in modules/
filter/ filter.admin.inc - Process filter order configuration form submission.
- filter_formats in modules/
filter/ filter.module - Retrieve a list of input formats.
- filter_format_allowcache in modules/
filter/ filter.module - Check if text in a certain input format is allowed to be cached.
- filter_list_format in modules/
filter/ filter.module - Retrieve a list of filters for a certain format.
- flood_is_allowed in includes/
common.inc - Check if the current visitor (hostname/IP) is allowed to proceed with the specified event.
- flood_register_event in includes/
common.inc - Register an event for the current visitor (hostname/IP) to the flood control mechanism.
- forum_get_forums in modules/
forum/ forum.module - Returns a list of all forums for a given taxonomy id
- forum_install in modules/
forum/ forum.install - Implementation of hook_install().
- forum_load in modules/
forum/ forum.module - Implementation of hook_load().
- forum_nodeapi in modules/
forum/ forum.module - Implementation of hook_nodeapi().
- forum_taxonomy in modules/
forum/ forum.module - Implementation of hook_taxonomy().
- forum_term_load in modules/
forum/ forum.module - Fetch a forum term.
- forum_uninstall in modules/
forum/ forum.install - Implementation of hook_uninstall().
- hook_actions_delete in developer/
hooks/ core.php - Execute code after an action is deleted.
- hook_cron in developer/
hooks/ core.php - Perform periodic actions.
- hook_delete in developer/
hooks/ node.php - Respond to node deletion.
- hook_exit in developer/
hooks/ core.php - Perform cleanup tasks.
- hook_file_download in developer/
hooks/ core.php - Control access to private file downloads and specify HTTP headers.
- hook_form_alter in developer/
hooks/ core.php - Perform alterations before a form is rendered.
- hook_insert in developer/
hooks/ node.php - Respond to node insertion.
- hook_load in developer/
hooks/ node.php - Load node-type-specific information.
- hook_search in developer/
hooks/ core.php - Define a custom search routine.
- hook_update in developer/
hooks/ node.php - Respond to node updating.
- hook_update_N in developer/
hooks/ install.php - Perform a single update.
- install_verify_drupal in ./
install.php - Verify if Drupal is installed.
- language_list in includes/
bootstrap.inc - Get a list of languages set up indexed by the specified key
- list_themes in includes/
theme.inc - Provides a list of currently available themes.
- locale in modules/
locale/ locale.module - Provides interface translation services.
- locale_add_language in includes/
locale.inc - API function to add a language.
- locale_batch_by_component in includes/
locale.inc - Prepare a batch to run when installing modules or enabling themes. This batch will import translations for the newly added components in all the languages already set up on the site.
- locale_batch_by_language in includes/
locale.inc - Prepare a batch to import translations for all enabled modules in a given language.
- locale_install in modules/
locale/ locale.install - Implementation of hook_install().
- locale_languages_delete_form_submit in includes/
locale.inc - Process language deletion submissions.
- locale_languages_edit_form in includes/
locale.inc - Editing screen for a particular language.
- locale_languages_edit_form_submit in includes/
locale.inc - Process the language editing form submission.
- locale_languages_edit_form_validate in includes/
locale.inc - Validate the language editing form. Reused for custom language addition too.
- locale_languages_overview_form_submit in includes/
locale.inc - Process language overview form submissions, updating existing languages.
- locale_languages_predefined_form_validate in includes/
locale.inc - Validate the language addition form.
- locale_translate_delete_form_submit in includes/
locale.inc - Process string deletion submissions.
- locale_translate_delete_page in includes/
locale.inc - String deletion confirmation page.
- locale_translate_edit_form in includes/
locale.inc - User interface for string editing.
- locale_translate_edit_form_submit in includes/
locale.inc - Process string editing form submissions.
- locale_translate_overview_screen in includes/
locale.inc - Overview screen for translations.
- locale_uninstall in modules/
locale/ locale.install - Implementation of hook_uninstall().
- locale_update_6000 in modules/
locale/ locale.install - {locales_meta} table became {languages}.
- locale_update_6005 in modules/
locale/ locale.install - Change language setting variable of content types.
- locale_update_6006 in modules/
locale/ locale.install - Neutralize unsafe language names in the database.
- lock_acquire in includes/
lock.inc - Acquire (or renew) a lock, but do not block if it fails.
- lock_may_be_available in includes/
lock.inc - Check if lock acquired by a different process may be available.
- lock_release in includes/
lock.inc - Release a lock previously acquired by lock_acquire().
- lock_release_all in includes/
lock.inc - Release all previously acquired locks.
- menu_delete_menu_confirm in modules/
menu/ menu.admin.inc - Build a confirm form for deletion of a custom menu.
- menu_delete_menu_confirm_submit in modules/
menu/ menu.admin.inc - Delete a custom menu and all items in it.
- menu_edit_menu_submit in modules/
menu/ menu.admin.inc - Submit function for adding or editing a custom menu.
- menu_edit_menu_validate in modules/
menu/ menu.admin.inc - Validates the human and machine-readable names when adding or editing a menu.
- menu_enable in modules/
menu/ menu.module - Implementation of hook_enable()
- menu_get_menus in modules/
menu/ menu.module - Return an associative array of the custom menus names.
- menu_get_names in includes/
menu.inc - Build a list of named menus.
- menu_install in modules/
menu/ menu.install - Implementation of hook_install().
- menu_link_delete in includes/
menu.inc - Delete one or several menu links.
- menu_link_load in includes/
menu.inc - Get a menu link by its mlid, access checked and link translated for rendering.
- menu_link_maintain in includes/
menu.inc - Insert, update or delete an uncustomized menu link related to a module.
- menu_link_save in includes/
menu.inc - Save a menu link.
- menu_load in modules/
menu/ menu.module - Load the data for a single custom menu.
- menu_local_tasks in includes/
menu.inc - Collects the local tasks (tabs) for a given level.
- menu_nodeapi in modules/
menu/ menu.module - Implementation of hook_nodeapi().
- menu_overview_form in modules/
menu/ menu.admin.inc - Form for editing an entire menu tree at once.
- menu_overview_page in modules/
menu/ menu.admin.inc - Menu callback which shows an overview page of all the custom menus and their descriptions.
- menu_tree_all_data in includes/
menu.inc - Get the data structure representing a named menu tree.
- menu_tree_check_access in includes/
menu.inc - Check access and perform other dynamic operations for each link in the tree.
- menu_tree_page_data in includes/
menu.inc - Get the data structure representing a named menu tree, based on the current page.
- menu_valid_path in includes/
menu.inc - Validates the path of a menu link being created or edited.
- module_disable in includes/
module.inc - Disable a given set of modules.
- module_enable in includes/
module.inc - Enable a given list of modules.
- module_list in includes/
module.inc - Collect a list of all loaded modules. During the bootstrap, return only vital modules. See bootstrap.inc
- module_rebuild_cache in includes/
module.inc - Rebuild the database cache of module files.
- node_access_rebuild in modules/
node/ node.module - Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.
- node_access_view_all_nodes in modules/
node/ node.module - Determine whether the user has a global viewing grant for all nodes.
- node_access_write_grants in modules/
node/ node.module - Writes a list of grants to the database, deleting any previously saved ones.
- node_admin_nodes in modules/
node/ node.admin.inc - Form builder: Builds the node administration overview.
- node_assign_owner_action in modules/
node/ node.module - Implementation of a configurable Drupal action. Assigns ownership of a node to a user.
- node_assign_owner_action_form in modules/
node/ node.module - node_assign_owner_action_submit in modules/
node/ node.module - node_assign_owner_action_validate in modules/
node/ node.module - node_comment_mode in modules/
node/ node.module - Retrieve the comment mode for the given node ID (none, read, or read/write).
- node_cron in modules/
node/ node.module - Implementation of hook_cron().
- node_delete in modules/
node/ node.module - Delete a node.
- node_last_changed in modules/
node/ node.module - node_last_viewed in modules/
node/ node.module - Retrieves the timestamp at which the current user last viewed the specified node.
- node_load in modules/
node/ node.module - Load a node object from the database.
- node_multiple_delete_confirm in modules/
node/ node.admin.inc - node_revision_delete_confirm_submit in modules/
node/ node.pages.inc - node_revision_list in modules/
node/ node.module - Return a list of all the existing revision numbers.
- node_save in modules/
node/ node.module - Save a node object into the database.
- node_search in modules/
node/ node.module - Implementation of hook_search().
- node_tag_new in modules/
node/ node.module - Update the 'last viewed' timestamp of the specified node for current user.
- node_type_delete in modules/
node/ node.module - Deletes a node type from the database.
- node_type_delete_confirm in modules/
node/ content_types.inc - Menu callback; delete a single content type.
- node_type_save in modules/
node/ node.module - Saves a node type to the database.
- node_type_update_nodes in modules/
node/ node.module - Updates all nodes of one type to be of another type.
- node_update_index in modules/
node/ node.module - Implementation of hook_update_index().
- node_user in modules/
node/ node.module - Implementation of hook_user().
- openid_association in modules/
openid/ openid.module - Attempt to create a shared secret with the OpenID Provider.
- openid_cron in modules/
openid/ openid.module - Remove expired nonces from the database.
- openid_user_add_validate in modules/
openid/ openid.pages.inc - openid_user_delete_form in modules/
openid/ openid.pages.inc - Present a confirmation form to delete the specified OpenID identity from the system.
- openid_user_delete_form_submit in modules/
openid/ openid.pages.inc - openid_user_identities in modules/
openid/ openid.pages.inc - Menu callback; Manage OpenID identities for the specified user.
- openid_verify_assertion in modules/
openid/ openid.module - Attempt to verify the response received from the OpenID Provider.
- openid_verify_assertion_nonce in modules/
openid/ openid.module - Verify that the nonce has not been used in earlier assertions from the same OpenID provider.
- pager_query in includes/
pager.inc - Perform a paged database query.
- path_admin_delete in modules/
path/ path.module - Post-confirmation; delete an URL alias.
- path_admin_form_validate in modules/
path/ path.admin.inc - Verify that a new URL alias is valid
- path_admin_overview in modules/
path/ path.admin.inc - Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
- path_form_alter in modules/
path/ path.module - Implementation of hook_form_alter().
- path_load in modules/
path/ path.module - Fetch a specific URL alias from the database.
- path_nodeapi in modules/
path/ path.module - Implementation of hook_nodeapi().
- path_set_alias in modules/
path/ path.module - Set an aliased path for a given Drupal path, preventing duplicates.
- php_install in modules/
php/ php.install - Implementation of hook_install().
- ping_cron in modules/
ping/ ping.module - Implementation of hook_cron().
- poll_block in modules/
poll/ poll.module - Implementation of hook_block().
- poll_cancel in modules/
poll/ poll.module - Submit callback for poll_cancel_form
- poll_cron in modules/
poll/ poll.module - Implementation of hook_cron().
- poll_delete in modules/
poll/ poll.module - Implementation of hook_delete().
- poll_insert in modules/
poll/ poll.module - Implementation of hook_insert().
- poll_load in modules/
poll/ poll.module - Implementation of hook_load().
- poll_update in modules/
poll/ poll.module - Implementation of hook_update().
- poll_user in modules/
poll/ poll.module - Implementation of hook_user().
- poll_vote in modules/
poll/ poll.module - Submit handler for processing a vote
- profile_admin_overview in modules/
profile/ profile.admin.inc - Form builder to display a listing of all editable profile fields.
- profile_admin_overview_submit in modules/
profile/ profile.admin.inc - Submit handler to update changed profile field weights and categories.
- profile_autocomplete in modules/
profile/ profile.pages.inc - Callback to allow autocomplete of profile text fields.
- profile_block in modules/
profile/ profile.module - Implementation of hook_block().
- profile_browse in modules/
profile/ profile.pages.inc - Menu callback; display a list of user information.
- profile_categories in modules/
profile/ profile.module - profile_category_access in modules/
profile/ profile.module - Menu item access callback - check if a user has access to a profile category.
- profile_field_delete in modules/
profile/ profile.admin.inc - Menu callback; deletes a field from all user profiles.
- profile_field_delete_submit in modules/
profile/ profile.admin.inc - Process a field delete form submission.
- profile_field_form in modules/
profile/ profile.admin.inc - Menu callback: Generate a form to add/edit a user profile field.
- profile_field_form_submit in modules/
profile/ profile.admin.inc - Process profile_field_form submissions.
- profile_field_form_validate in modules/
profile/ profile.admin.inc - Validate profile_field_form submissions.
- profile_load_profile in modules/
profile/ profile.module - profile_save_profile in modules/
profile/ profile.module - profile_user in modules/
profile/ profile.module - Implementation of hook_user().
- profile_view_profile in modules/
profile/ profile.module - search_index in modules/
search/ search.module - Update the full-text search index for a particular item.
- search_nodeapi in modules/
search/ search.module - Implementation of hook_nodeapi().
- search_touch_node in modules/
search/ search.module - Change a node's changed timestamp to 'now' to force reindexing.
- search_update_totals in modules/
search/ search.module - This function is called on shutdown to ensure that search_total is always up to date (even if cron times out or otherwise fails).
- search_wipe in modules/
search/ search.module - Wipes a part of or the entire search index.
- sess_count in includes/
session.inc - Counts how many users have sessions. Can count either anonymous sessions or authenticated sessions.
- sess_destroy_sid in includes/
session.inc - Called by PHP session handling with the PHP session ID to end a user's session.
- sess_destroy_uid in includes/
session.inc - End a specific user's session
- sess_gc in includes/
session.inc - sess_read in includes/
session.inc - Reads an entire session from the database (internal use only).
- sess_regenerate in includes/
session.inc - Called when an anonymous user becomes authenticated or vice-versa.
- sess_write in includes/
session.inc - Writes an entire session to the database (internal use only).
- statistics_access_log in modules/
statistics/ statistics.admin.inc - Menu callback; Displays recent page accesses.
- statistics_cron in modules/
statistics/ statistics.module - Implementation of hook_cron().
- statistics_exit in modules/
statistics/ statistics.module - Implementation of hook_exit().
- statistics_get in modules/
statistics/ statistics.module - Retrieves a node's "view statistics".
- statistics_nodeapi in modules/
statistics/ statistics.module - Implementation of hook_nodeapi().
- statistics_user in modules/
statistics/ statistics.module - Implementation of hook_user().
- system_actions_configure in modules/
system/ system.module - Menu callback. Create the form for configuration of a single action.
- system_actions_manage in modules/
system/ system.module - Menu callback. Display an overview of available and configured actions.
- system_admin_menu_block in modules/
system/ system.module - Provide a single block on the administration overview page.
- system_admin_theme_submit in modules/
system/ system.module - Process admin theme form submissions.
- system_cron in modules/
system/ system.module - Implementation of hook_cron().
- system_get_files_database in modules/
system/ system.module - Retrieves the current status of an array of files in the system table.
- system_get_module_admin_tasks in modules/
system/ system.module - Generate a list of tasks offered by a specified module.
- system_initialize_theme_blocks in modules/
system/ system.module - Assign an initial, default set of blocks for a theme.
- system_install in modules/
system/ system.install - Implementation of hook_install().
- system_main_admin_page in modules/
system/ system.admin.inc - Menu callback; Provide the administration overview page.
- system_modules_submit in modules/
system/ system.admin.inc - Submit callback; handles modules form submission.
- system_modules_uninstall in modules/
system/ system.admin.inc - Builds a form of currently disabled modules.
- system_region_list in modules/
system/ system.module - Get a list of available regions from a specified theme.
- system_sql in modules/
system/ system.admin.inc - Menu callback: return information about the database.
- system_status in modules/
system/ system.admin.inc - Menu callback: displays the site status report. Can also be used as a pure check.
- system_themes_form_submit in modules/
system/ system.admin.inc - Process system_themes_form form submissions.
- system_theme_data in modules/
system/ system.module - Collect data about all currently available themes.
- system_update_6000 in modules/
system/ system.install - Remove auto_increment from {boxes} to allow adding custom blocks with visibility settings.
- system_update_6001 in modules/
system/ system.install - Add version id column to {term_node} to allow taxonomy module to use revisions.
- system_update_6009 in modules/
system/ system.install - The PHP filter is now a separate module.
- system_update_6018 in modules/
system/ system.install - Add HTML corrector to HTML formats or replace the old module if it was in use.
- system_update_6019 in modules/
system/ system.install - Reconcile small differences in the previous, manually created mysql and pgsql schemas so they are the same and can be represented by a single schema structure.
- system_update_6021 in modules/
system/ system.install - Migrate the menu items from the old menu system to the new menu_links table.
- system_update_6027 in modules/
system/ system.install - Add block cache.
- system_update_6034 in modules/
system/ system.install - Rename permission "administer access control" to "administer permissions".
- system_update_6036 in modules/
system/ system.install - Change the search schema and indexing.
- system_update_6039 in modules/
system/ system.install - Rename permissions "edit foo content" to "edit any foo content". Also update poll module permission "create polls" to "create poll content".
- system_update_6041 in modules/
system/ system.install - Change forum vocabulary not to be required by default and set the weight of the forum.module 1 higher than the taxonomy.module.
- system_update_6045 in modules/
system/ system.install - Update blog, book and locale module permissions.
- taxonomy_del_term in modules/
taxonomy/ taxonomy.module - Delete a term.
- taxonomy_del_vocabulary in modules/
taxonomy/ taxonomy.module - Delete a vocabulary.
- taxonomy_form_alter in modules/
taxonomy/ taxonomy.module - Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node. We check for taxonomy_override_selector before loading the full vocabulary, so contrib modules can intercept before hook_form_alter and provide scalable…
- taxonomy_get_children in modules/
taxonomy/ taxonomy.module - Find all children of a term ID.
- taxonomy_get_parents in modules/
taxonomy/ taxonomy.module - Find all parents of a given term ID.
- taxonomy_get_related in modules/
taxonomy/ taxonomy.module - Find all term objects related to a given term ID.
- taxonomy_get_synonyms in modules/
taxonomy/ taxonomy.module - Return an array of synonyms of the given term ID.
- taxonomy_get_synonym_root in modules/
taxonomy/ taxonomy.module - Return the term object that has the given string as a synonym.
- taxonomy_get_term in modules/
taxonomy/ taxonomy.module - Return the term object matching a term ID.
- taxonomy_get_term_by_name in modules/
taxonomy/ taxonomy.module - Try to map a string to an existing term, as for glossary use.
- taxonomy_get_tree in modules/
taxonomy/ taxonomy.module - Create a hierarchical representation of a vocabulary.
- taxonomy_get_vocabularies in modules/
taxonomy/ taxonomy.module - Return an array of all vocabulary objects.
- taxonomy_node_delete in modules/
taxonomy/ taxonomy.module - Remove associations of a node to its terms.
- taxonomy_node_delete_revision in modules/
taxonomy/ taxonomy.module - Remove associations of a node to its terms.
- taxonomy_node_get_terms in modules/
taxonomy/ taxonomy.module - Find all terms associated with the given node, ordered by vocabulary and term weight.
- taxonomy_node_get_terms_by_vocabulary in modules/
taxonomy/ taxonomy.module - Find all terms associated with the given node, within one vocabulary.
- taxonomy_node_save in modules/
taxonomy/ taxonomy.module - Save term associations for a given node.
- taxonomy_node_type in modules/
taxonomy/ taxonomy.module - Implementation of hook_node_type().
- taxonomy_overview_terms in modules/
taxonomy/ taxonomy.admin.inc - Form builder for the taxonomy terms overview.
- taxonomy_save_term in modules/
taxonomy/ taxonomy.module - Helper function for taxonomy_form_term_submit().
- taxonomy_save_vocabulary in modules/
taxonomy/ taxonomy.module - taxonomy_term_count_nodes in modules/
taxonomy/ taxonomy.module - Count the number of published nodes classified by a term.
- taxonomy_term_page in modules/
taxonomy/ taxonomy.pages.inc - Menu callback; displays all nodes associated with a term.
- taxonomy_vocabulary_confirm_reset_alphabetical_submit in modules/
taxonomy/ taxonomy.admin.inc - Submit handler to reset a vocabulary to alphabetical order after confirmation.
- taxonomy_vocabulary_load in modules/
taxonomy/ taxonomy.module - Return the vocabulary object matching a vocabulary ID.
- template_preprocess_forum_topic_navigation in modules/
forum/ forum.module - Preprocess variables to format the next/previous forum topic navigation links.
- translation_nodeapi in modules/
translation/ translation.module - Implementation of hook_nodeapi().
- translation_node_get_translations in modules/
translation/ translation.module - Get all nodes in a translation set, represented by $tnid.
- translation_remove_from_set in modules/
translation/ translation.module - Remove a node from its translation set (if any) and update the set accordingly.
- trigger_actions_delete in modules/
trigger/ trigger.module - Implementation of hook_actions_delete().
- trigger_assign_form_submit in modules/
trigger/ trigger.admin.inc - Submit function for trigger_assign_form().
- trigger_assign_form_validate in modules/
trigger/ trigger.admin.inc - Validation function for trigger_assign_form().
- trigger_menu in modules/
trigger/ trigger.module - Implementation of hook_menu().
- trigger_unassign_submit in modules/
trigger/ trigger.admin.inc - update_fix_compatibility in ./
update.php - Disable anything in the {system} table that is not compatible with the current version of Drupal core.
- update_sql in includes/
database.inc - Perform an SQL query and return success or failure.
- upload_delete in modules/
upload/ upload.module - upload_delete_revision in modules/
upload/ upload.module - upload_file_download in modules/
upload/ upload.module - Implementation of hook_file_download().
- upload_load in modules/
upload/ upload.module - upload_save in modules/
upload/ upload.module - upload_total_space_used in modules/
upload/ upload.module - Determine how much disk space is occupied by uploaded files.
- user_access in modules/
user/ user.module - Determine whether the user has a given privilege.
- user_admin_access in modules/
user/ user.admin.inc - Menu callback: list all access rules
- user_admin_access_delete_confirm in modules/
user/ user.admin.inc - Menu callback: delete an access rule
- user_admin_access_delete_confirm_submit in modules/
user/ user.admin.inc - user_admin_access_edit in modules/
user/ user.admin.inc - Menu callback: edit an access rule.
- user_admin_access_form_submit in modules/
user/ user.admin.inc - Submit callback for user_admin_access_form().
- user_admin_account in modules/
user/ user.admin.inc - Form builder; User administration page.
- user_admin_perm in modules/
user/ user.admin.inc - Menu callback: administer permissions.
- user_admin_perm_submit in modules/
user/ user.admin.inc - user_admin_role in modules/
user/ user.admin.inc - Menu callback: administer roles.
- user_admin_role_submit in modules/
user/ user.admin.inc - user_admin_role_validate in modules/
user/ user.admin.inc - user_authenticate_finalize in modules/
user/ user.module - Finalize the login process. Must be called when logging in a user.
- user_block in modules/
user/ user.module - Implementation of hook_block().
- user_block_ip_action in modules/
user/ user.module - Implementation of a Drupal action. Adds an access rule that blocks the user's IP address.
- user_block_user_action in modules/
user/ user.module - Implementation of a Drupal action. Blocks the current user.
- user_delete in modules/
user/ user.module - Delete a user.
- user_external_load in modules/
user/ user.module - user_fields in modules/
user/ user.module - user_get_authmaps in modules/
user/ user.module - Discover which external authentication module(s) authenticated a username.
- user_is_blocked in modules/
user/ user.module - Checks for usernames blocked by user administration.
- user_load in modules/
user/ user.module - Fetch a user object.
- user_multiple_delete_confirm in modules/
user/ user.module - user_multiple_role_edit in modules/
user/ user.module - Callback function for admin mass adding/deleting a user role.
- user_roles in modules/
user/ user.module - Retrieve an array of roles matching specified conditions.
- user_save in modules/
user/ user.module - Save changes to a user account or add a new user.
- user_set_authmaps in modules/
user/ user.module - Save mappings of which external authentication module(s) authenticated a user. Maps external usernames to user ids in the users table.
- variable_del in includes/
bootstrap.inc - Unsets a persistent variable.
- variable_init in includes/
bootstrap.inc - Load the persistent variable table.
- variable_set in includes/
bootstrap.inc - Sets a persistent variable.
- _aggregator_has_categories in modules/
aggregator/ aggregator.module - Find out whether there are any aggregator categories.
- _batch_finished in includes/
batch.inc - End the batch processing: Call the 'finished' callbacks to allow custom handling of results, and resolve page redirection.
- _batch_page in includes/
batch.inc - State-based dispatcher for the batch processing page.
- _batch_shutdown in includes/
batch.inc - Shutdown function: store the batch data for next request, or clear the table if the batch is finished.
- _block_rehash in modules/
block/ block.module - Update the 'blocks' DB table with the blocks currently exported by modules.
- _blogapi_space_used in modules/
blogapi/ blogapi.module - _book_update_outline in modules/
book/ book.module - Common helper function to handles additions and updates to the book outline.
- _comment_delete_thread in modules/
comment/ comment.admin.inc - Perform the actual deletion of a comment and all its replies.
- _comment_load in modules/
comment/ comment.module - Load the entire comment by cid.
- _comment_update_node_statistics in modules/
comment/ comment.module - Updates the comment statistics for a given node. This should be called any time a comment is added, deleted, or updated.
- _dblog_get_message_types in modules/
dblog/ dblog.module - _filter_tips in modules/
filter/ filter.module - Helper function for fetching filter tips.
- _forum_topics_unread in modules/
forum/ forum.module - Calculate the number of nodes the user has not yet read and are newer than NODE_NEW_LIMIT.
- _forum_user_last_visit in modules/
forum/ forum.module - _locale_export_get_strings in includes/
locale.inc - Generates a structured array of all strings with translations in $language, if given. This array can be used to generate an export of the string in the database.
- _locale_import_one_string in includes/
locale.inc - Imports a string into the database
- _locale_import_one_string_db in includes/
locale.inc - Import one string into the database.
- _locale_import_po in includes/
locale.inc - Parses Gettext Portable Object file information and inserts into database
- _locale_parse_js_file in includes/
locale.inc - Parses a JavaScript file, extracts strings wrapped in Drupal.t() and Drupal.formatPlural() and inserts them into the database.
- _locale_rebuild_js in includes/
locale.inc - (Re-)Creates the JavaScript translation file for a language.
- _menu_delete_item in includes/
menu.inc - Helper function for menu_link_delete; deletes a single menu link.
- _menu_link_move_children in includes/
menu.inc - Update the children of a menu link that's being moved.
- _menu_navigation_links_rebuild in includes/
menu.inc - Helper function to build menu links for the items in the menu router.
- _menu_router_build in includes/
menu.inc - Helper function to build the router table based on the data from hook_menu.
- _menu_set_expanded_menus in includes/
menu.inc - Helper function to update a list of menus with expanded items
- _menu_update_parental_status in includes/
menu.inc - Check and update the has_children status for the parent of a link.
- _node_access_rebuild_batch_operation in modules/
node/ node.module - Batch operation for node_access_rebuild_batch.
- _node_revision_access in modules/
node/ node.module - _node_types_build in modules/
node/ node.module - Builds and returns the list of available node types.
- _profile_get_fields in modules/
profile/ profile.module - _taxonomy_term_children in modules/
taxonomy/ taxonomy.module - Helper for taxonomy_term_count_nodes(). Used to find out which terms are children of a parent term.
- _trigger_get_hook_actions in modules/
trigger/ trigger.admin.inc - Get the actions that have already been defined for this type-hook-op combination.
- _trigger_get_hook_aids in modules/
trigger/ trigger.module - Get the aids of actions to be executed for a hook-op combination.
- _update_cache_clear in modules/
update/ update.module - Invalidates specific cached data relating to update status.
- _update_cache_get in modules/
update/ update.module - Retrieve data from the private update status cache table.
- _update_cache_set in modules/
update/ update.module - Store data in the private update status cache table.
- _user_edit_validate in modules/
user/ user.module
File
- includes/
database.pgsql.inc, line 115 - Database interface code for PostgreSQL database servers.
Code
<?php
function db_query($query) {
$args = func_get_args();
array_shift($args);
$query = db_prefix_tables($query);
if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
$args = $args[0];
}
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
return _db_query($query);
}
?> Login or register to post comments
Comments
Must use arguments to store serialized data
Note that to store serialized data, it must be passed as an argument or it will be corrupted by db_query. The following example shows how to store serialized arrays:
$result = db_query("INSERT INTO {my_table}(name, description, array1, array2)
VALUES ('something', 'something else', '%s', '%s')",
serialize($myarray1), serialize($myarray2)
);
db_query("INSERT...") is discouraged
As of Drupal 6, data can be inserted into the database using drupal_write_record(), and the fields can be noted as "'serialize' => true" when declared in hook_schema(). drupal_write_record() will then serialize your data for you and everything.
<?php$data = array(
'name' => 'something',
'description' => 'something else',
'array1' => $myarray1,
'array2' => $myarray2
);
drupal_write_record('my_table', $data);
?>
Would you like to know more?
drupal_write_record() only inserts one data object, though
But there doesn't seem to be a way to do insert of multiple value, for example:
INSERT INTO `table` (`id`,`value`) VALUES (1, 'one'), (2, 'two');I guess it isn't be too hard for Drupal to provide an API function for that. Maybe not enough demand?
Drupal 7 overhauls the Database API
In D7 db_insert supports multiple insertion
ww9rivers is correct. If
ww9rivers is correct. If you're inserting using large volumes (100 or more) in short form syntax, then use db_query, not drupal_write_record.
DR6 drupal_write_record does validation per record, then individual inserts (does DR7 do the same? the documentation is out of date if it handles multiples) effectively losing the bandwidth, memory and speed advantages of multiple inserts per sql expression.
Yes
Yes, in that case use db_query. It's discouraged but not deprecated, and may be used where appropriate ;)
I think you would prefer
I think you would prefer wrapping all your arguments in the same array, according to the function signature :
$result = db_query("INSERT INTO {my_table}(name, description, array1, array2)
VALUES ('something', 'something else', '%s', '%s')",
array(serialize($myarray1), serialize($myarray2))
);
Placeholder | Meaning
Placeholder | Meaning
%s | String
%d | Integer
%b | Binary
%% | Inserts a literal % sign
%f | Float
sprintf function
Which most likely use or is based on sprintf().
date data assignment?
how about the date data type?
can you explain about the date?
with IN()
Here's an example how to use
db_query()properly withIN(). I spent some time looking for this information, so maybe I can save someone else the time.Selecting nodes with a certain set of terms from
{term_node}:<?php$tids; // An array of term IDs
$placeholders = implode(', ', array_fill(0, count($tids), "%d"));
$r = db_query("SELECT nid FROM {term_node} WHERE tid IN ($placeholders)", $tids);
?>
db_placeholders
<?php$tids; // An array of term IDs
$placeholders = implode(', ', array_fill(0, count($tids), "%d"));
?>
Thats exactly what db_placeholders() does...
db_placeholders does not exist in D7
nt
A word of caution
This has gotten me twice and its a pain to debug. If your second argument to the function is an array, all following arguments are ignored and not used as expected in the query. See the lines around the comment // 'All arguments in one array' syntax. If you must pass an array of arguments make sure it has ALL your arguments. This means you can't do a query like the following:
<?php$tids; // An array of term IDs
$type; // string identifying a content type.
$placeholders = implode(', ', array_fill(0, count($tids), "%d"));
$r = db_query("SELECT nid FROM {term_node} WHERE tid IN ($placeholders) and type='%s'", $tids, $type);
?>
If you use db_queryd from the devel module, the sql statement generated will be:
SELECT nid from term_node WHERE tid in (1,2,3,4,5) and type=''
This works for me
<?php
$tids; // An array of term IDs
$type; // string identifying a content type.
$args = array_merge($tids, array($type));
$r = db_query("SELECT nid FROM {term_node} WHERE tid IN (".db_placeholders($tids, 'int').") AND type='%s'", $args);
?>
Hope that helps! took hours to find a fix
However wondered how to print the results?
Here is a post that provides some examples how to print the result of your query:
http://drupal.org/node/567786
Fun and easy
Combine db_fetch_array and theme_table for fun and profit!
<?php$q = db_query($query);
while ($r = db_fetch_array($q)) {
$rows[] = $r;
}
print theme('table', $header, $rows);
?>
This is the simplest example - you can have even more fun by adding a $header array with references to the fields in your table, and appending your $query with the result of tablesort_sql($header)...
<?php$query = "SELECT field_1, field_2, field_3 FROM {mytable}";
$header = array(
array('data' => t('Cell 1'), 'field' => 'field_1', 'sort' => 'ASC'),
array('data' => t('Cell 2'), 'field' => 'field_2'),
array('data' => t('Cell 3'), 'field' => 'field_3'),
);
$q = db_query($query . tablesort_sql($header));
while ($r = db_fetch_array($q)) {
$rows[] = $r;
}
print theme('table', $header, $rows);
?>
Checking result
Be aware that the result that comes back can be empty so to ensure that there is at least one entry, you can do this:
<?php
$query = "SELECT...";
$result = db_query($query);
if (count($result) > 0) {
$data = db_fetch_array($result);
if ($data != FALSE) {
// there is at least one result data
}
}
?>
Note, $result is an object, not an array and so you cannot use PHP's empty() function to check to see if it is empty.
Dereferencing $result
You can't depend on count($result) getting what you want. $result will be a different type depending on the database backend you're using. Only use the functions listed in the database API on $result.
If you need to find the number of items returned by a query, use the SQL COUNT() function.
If you need to find out if you got any data back at all, check if the return value of db_fetch_array($result), db_result($result), or db_fetch_object($result) is FALSE.
<?php
$result = db_query('SELECT a, b, c FROM d WHERE e > 25');
$no_results = TRUE;
while ($row = db_fetch_array($result)) {
$no_results = FALSE;
$output .= 'a = ' . $row['a'] . ', b = ' . $row['b'] . ' , and c = ' . $row['c'] . '<br />';
}
if ($no_results) {
$output = '<p>' . t('No results found for e greater than 25!') . '</p>';
}
?>
PostgreSQL query compatibility
In PostgreSQL queries, %s have to be enclosed in apostrophes ( ' ), quotation marks ( " ) will not work.
If a query that has % in
If a query that has % in them, like in a mysql DATEFORMAT(%Y-%d-%m). You need to add a second % like this DATEFORMAT(%%Y-%%d-%%m) the % needs to be escaped so that db_query doesn't try to replace it.
Saved my day!! yay!
Saved my day!! yay!
Thanks! It is easy to miss
Thanks!
It is easy to miss the %b.
There is no
There is no documentation/example for $options. For each API function documentation, adding one example that covers all the parameters will be of great help.
Simple Example
A missing simple example
<?phpdb_query("SELECT * FROM {node} WHERE nid=%d AND title = '%s', $nid, $title");
?>
simple example mistake...
The previous example will not work, the right example would be:
<?phpdb_query("SELECT * FROM {node} WHERE nid=%d AND title = '%s'", $nid, $title);
?>
It doesn't work at all
here what I need:
$activation = '1';$query = db_query("SELECT SUM(active_payments) FROM payments WHERE uid = %d AND verified = '%s'" , $what_user, $activation);
Here what it tells:
Recoverable fatal error: Argument 2 passed to db_query() must be an array, string given, called in /web/htdocs/www.mysite.com/home/modules/php/php.module(74) : eval()'d code on line 180 and defined in db_query() (line 2309 of /web/htdocs/www.mysite.com/home/includes/database/database.inc).
when using db_query()
Using db_query() is a good function for database handling thus it already have been altered to make a compatibility on different database.
db_query() automatically escapes operation that are concatenated at the string arguments and causes to produce unwanted result so database query will show an error.
here's a sample code:
<?php$foo = 100;
db_query("SELECT * FROM `bar` WHERE foo = `" . $foo + 1 . ");
//This would produce error in the query.
?>
The proper way around would be:
<?php$foo = 100;
$added_foo = $foo + 1;
db_query("SELECT * FROM `bar` WHERE foo = `" . $added_foo + 1 . ");
?>
or like what garen24 have said...
<?phpdb_query("SELECT * FROM {node} WHERE nid=%d AND title = '%s'", $nid, $title);
?>
hope this helps.
WIldcards...
So how can you correctly use a simple wildcard like this within a sql query for Drupal?
SELECT name Nombre, mail Email
FROM users
WHERE status = 1
AND mail LIKE ('%@hotmail%')
LIMIT 25
Cause I am getting this error:
Division by zero in /home/mysite/www2/dev/sites/all/modules/onthisdate/onthisdate.module in line 38.
try this
LIKE '%%@hotmail%%'