I'm quite new to drupal (and PHP) but already starting to like it a lot!
To learn the internals I started poking around inside the ecomerce module and found this
/**
* The names of the database columns in the table.
*/
function product_fields($table = 'ec_product') {
return array('nid', 'sku', 'price', 'is_recurring', 'price_interval', 'price_unit', 'price_cycle', 'auto_charge', 'ptype', 'hide_cart_link');
}
If prefer to make these kind of things automatic. After reading this I put together the following function:
function my_db_get_table_field_names($table) {
// Druplifed version of solution found at:
// http://se2.php.net/manual/en/function.mysql-list-fields.php
$sql = "SHOW COLUMNS FROM `$table`";
$field_names = array();
$result = db_query($sql);
for($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_array($result);
$name = $row['Field'];
array_push($field_names, $name);
}
return $field_names;
}
I've tried to search drupal.org to see if there is something similar already in Drupal but couldn't find anything.
Is this something people would like to have in future versions of database.mysql.inc? If not, what is the best way for me to assemble a library of useful functions - is it a module or a .inc-fi