Search code examples
phpdatabasedrupal-7drupal-modules

Need to debug db_insert but no error given


I have a custom module in a D7 installation.

In the submit function I'm doing the following:

my_custom_block_get_form_submit($form, &$form_state) {

$d = db_insert('db_launch')
->fields(array(
'uniq' => $uniq
))
->execute();

After executing the code, I get no errors in the error log, and the sites returns the standard "This website has encountered an error".

Does anyone have idea how I can debug this? I tried a try catch block but that didn't return anything.

Thanks,


Solution

  • To debug this code, you should try doing it this way:

    $query = db_insert('db_launch')
    ->fields(array(
    'uniq' => $uniq
    ));
    
    echo (string) $query ; // This will output your query that would be created with an insert.
    
    $d = $query->execute(); // and later on you can attach the output result.
    

    Note that, this will return the query with placeholders. If you wish to obtain the queries with actual values, you should have devel.module enabled and then:

    echo dpq($query) ; // This will output your query without placeholders