Active
Project:
Helpers
Version:
5.x-1.1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2009 at 00:45 UTC
Updated:
31 Jul 2009 at 00:45 UTC
Suggested helper functions in helpers_database module:
Additional functions in dra_mysql.inc:
/**
* The following should be placed in helpers_database.module
*/
/**
* Fields resulting from executing a query
*
* called similar to be db_query
* @return array of fields resulting from executing the query
function db_get_fields($query) {
$args = func_get_args();
array_shift($args);
$result = db_query($query, $args);
return db_fetch_fields($result);
}
/**
* @return array of fields of a query result
*/
function db_fetch_fields($result) {
if ($result) {
for($i = 0; $i < db_num_fields($result); $i++) {
$fields[] = db_field_name($result, $i);
}
}
return $fields;
}
/**
* The following should be placed in dra_mysql.inc
*/
/**
* @param $result
* A database query result resource, as returned from db_query().
* @return
* int or FALSE
* Returns the number of fields in the resource, or FALSE if cannot determine the number of fields
*/
function db_num_fields($result) {
return mysql_num_fields($result);
}
/**
* @param $result
* A database query result resource, as returned from db_query().
* @param $field_offset
* int Field offset in the result resource
* @return
* string Name of the field in the resource as the field_offset
*/
function db_field_name($result, $field_offset = 0) {
$args = func_get_args();
return call_user_func_array('mysql_field_name', $args);
}
/**
* @param $result
* A database query result resource, as returned from db_query().
* @param $field_offset
* int Field offset in the result resource
* @return
* string Type of the field in the resource as the field_offset
*/
function db_field_type($result, $field_offset = 0) {
$args = func_get_args();
return call_user_func_array('mysql_field_type', $args);
}
/**
* @param $result
* A database query result resource, as returned from db_query().
* @param $field_offset
* int Field offset in the result resource
* @return
* string Length of the field in the resource as the field_offset
*/
function db_field_len($result, $field_offset = 0) {
$args = func_get_args();
return call_user_func_array('mysql_field_len', $args);
}
/**
* @param $result
* A database query result resource, as returned from db_query().
* @param $field_offset
* int Field offset in the result resource
* @return
* string Flags of the field in the resource as the field_offset
*/
function db_field_flags($result, $field_offset = 0) {
$args = func_get_args();
return call_user_func_array('mysql_field_flags', $args);
}
/**
* @param $result
* A database query result resource, as returned from db_query().
* @param $field_offset
* int Field offset in the result resource
* @return
* string Table associated with the field in the resource as the field_offset
*/
function db_field_table($result, $field_offset = 0) {
$args = func_get_args();
return call_user_func_array('mysql_field_table', $args);
}