The MU forums have moved to

Trouble Inserting Into Database (8 posts)

  1. minidak03
    Posted 16 years ago #

    Hey just to quickly point out I'm not new to PHP and I'm not new to wordpress or MU so no need to make things easy here but I've got a question for everyone.

    That question is anyone else having one heck of a time getting WPMU to properly add information to there database, for instance I've got a program which runs out grabs some information, creates an array, serializes it (So I can keep the array status) then fails to enter it into the database.

    I've tried the following which should work but makes me wonder how much of the core WordPress MU hacked apart.

    $wpdb->query("INSERT INTO ".$table_prefix."Table (cell) VALUES ('cell_value')");

    That used to work just fine with Wordpress but not with MU, also I tried the wrong way to insert with the following.

    $wpdb->get_results("INSERT INTO ".$table_prefix."Table (cell) VALUES ('cell_value')");

    To no avail, I've tripple checked and quadrupal verified every line of my code which took me forever to do and the only thing that makes sense at this point is that MU hacked at the core $wpdb object class and screwed something up.

    Trust me its not the first time I'd have to fix the work done on MU.

    Just basically curious to see if anyone else had trouble adding to the database and how did you fix it?

    Thanks Everyone.

  2. lunabyte
    Posted 16 years ago #

    Do NOT use table_prefix, for starters. It's been deprecated.

    Use $wpdb->prefix instead. Or $wpdb->base_prefix for a global table.

  3. minidak03
    Posted 16 years ago #


    Thanks I'll give those a shot and get back to this.

  4. lunabyte
    Posted 16 years ago #

    Other than that, I'm using wpdb->query, get_results, etc. and all function as expected. Unless the query itself is malformed or something.

  5. minidak03
    Posted 16 years ago #

    No I've double checked the queries in regular mySQL form and they are all good.

    I changed out all the $table_prefix with $wpdb->prefix and that seemed to work at first but its glitchy at best.

    For instance sometimes it'll add the entries to the database sometimes but others it won't.

    At first I thought that it was because I was adding a hundred entries at once but I cut that back to 10 entries and not even adding them quickly its like adding 10 entries over about 1.5 to 2 minutes as the script runs, I've tried putting a delay ect..

    Figured it might be a MySQL problem with inserting them but I've hit the database much much much harder in the past with no problems.

    Strange I'll have to figure this thing out somehow.

  6. minidak03
    Posted 16 years ago #

    Oh my god I feel like such an idiot if this proves to be the problem.

    I was just looking at the code and it hit me that I wasent escaping my input strings, I wasen't using anything like mysql_real_escape_string() which could easily explain why some posts would get added while others would not.

    It seems to be ok I only did a couple tests I'll have to run a whole lot more to know 100%.

    Also does anyone know if the $wpdb->escape() function is still valid cause I used that before trying mysql_real_escape_string() and it didn't seem to fix the issue while mysql_real_escape_string() seems to be working.

  7. easysleeper
    Posted 15 years ago #

    I know this is over a year old, but is there a tutorial that covers this?

    Like a basic function that will take information passed in and insert it based on userid or something?


  8. stevejohnson
    Posted 15 years ago #

About this Topic

  • Started 16 years ago by minidak03
  • Latest reply from stevejohnson