2

enter image description here I am writing a query for inserting data in to database but when I am printing query at output it turns into "SHOW COLUMNS from tbl_name" query. I am writing below query . But it executes like shown in image

$table_name1 = $wpdb->prefix . 'fullcontact';
    $sql1=$wpdb->insert( $table_name1, array(
        'status' => $status,
        'request_id' => $req_id,
        'likelihood' => $likelihood,
        'photos' => $photos,
        'chats' => $chats,
        'websites' => $websites,
        'fullname' => $fullname,
        'familyname' => $familyname,
        'givenname' => $givenname,
        'organisation' => $organisation,
        'normalizedlocation' => $normalizedlocation,
        'city' => $city,
        'state' => $state,
        'country' => $country,
        'age' => $age,
        'agerange' => $agerange,
        'gender' => $gender,
        'locationgeneral' => $locationgeneral,
        'socialprofiles' => $socialprofiles,
        'scores' => $scores,
        'topics' => $topics
    ) );

    //exit( var_dump( $wpdb->last_query ) );
    $wpdb->show_errors();
    $wpdb->print_error($sql1);
5
  • 1
    Please elaborate on "printing query". What exactly are you doing and in what order? Commented Jun 6, 2017 at 7:55
  • $table_name1 = $wpdb->prefix . 'fullcontact'; $sql1=$wpdb->insert( $table_name1, array( 'status' => $status, 'request_id' => $req_id, 'likelihood' => $likelihood ) ); $wpdb->show_errors(); $wpdb->print_error($sql1); Commented Jun 6, 2017 at 8:56
  • i am printing this query by show_error() and print_error() function Commented Jun 6, 2017 at 8:56
  • I don't quite follow what you are trying to do there. Why explicit print_error() with result of your query? Commented Jun 6, 2017 at 9:05
  • can I mail you the pics plz ? I am hard stuck at this..it wud be kind if you help me. Commented Jun 6, 2017 at 9:10

2 Answers 2

5

For anyone else finding this question. Wordpress seems to do a SHOW FULL COLUMNS query before executing the INSERT query. If it determines that the INSERT query would fail/store bad data, for example because the given data types would not fit in the column, it does not execute the insert query at all and return false.

Check:

  • Have you filled all fields that can not be null and do not have a default value
  • Does the data type for every field match the data type in the database
  • Does the data passed to the function violate any constraints? A string cannot be longer than the maximum length of the field you are trying to put it into. An integer field has a minimum and maximum value. Unsigned integers cannot contain negative values.
2
  • Exactly.. I had did this in past and it worked..! Commented Jul 20, 2017 at 12:48
  • Appreciate this note, very helpful Commented Feb 13, 2023 at 18:13
0

Just had the same Problem, the fix was i tried to add varchar longer than the database field can hold. When changed the DB it workled again

1
  • thank You but it did'nt worked for me..anything else please ? Commented Jun 6, 2017 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.