I created a custom table in my modules .install file and I am asking for some form input in a custom made configuration file. I am unable to retrieve that data and print it out in a custom callback page that i created for testing. I’m not quite sure what i am doing wrong.
<?php /* mymodule.install */ function mymodule_schema(){ $ schema['mymodule'] = array( 'description' => 'Table for testing', 'fields' => array( 'pmid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'field_one' => array( 'description' => 'Field 1', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '' ), 'primary key' => array('pmid'), 'unique keys' => array( 'pmid' => array('pmid'), ), ), ); /* mymodule.module */ function mymodule_form_submit($ form, &$ form_state){ db_insert('mymodule') ->fields(array( 'field_one' => $ form_state['values']['field_one'], 'pmid' => 1, ))->execute(); } function mymodule_print_table(){ $ result = db_select('mymodule', 'mm') ->fields('field_one') ->execute() ->fetchAll(); var_dump($ result); }
This prints an empty array for me.