mySQL INSERT Statements and phpMyAdmin

If you’re a non-technical person, read the title and get a hint. ;) Of course, you’re welcome to stay, but you’ll probably be bored.

Now down to the meat of it.

phpMyAdmin is a sweet tool for messing with your mySQL databases. But for some reason, in most versions (all that I’ve used), it really botches up the PHP code it spits out for you to use in your own PHP scripts. So as a service to all you PHP coders out there, here’s how it’s supposed to look:

INSERT INTO TableName (ID, Name, Address, Phone, City, State) VALUES ('', 'Billy Bob', '123 Main Street', NULL, 'New York', 'NY')

Your variable would then look something like this:


Or more accurately, like this:

$SQL = "INSERT INTO TableName (ID, Name, Address, Phone, City, State) VALUES ('', 'Billy Bob', '123 Main Street', NULL, 'New York', 'NY')";

Now don’t say I never gave you nuthin’. It’s bad grammar.

  1. is it something that has to do with making the SQL export data universal to run between MSSQL and MySQL and SuperSQL YourSQL MrSQRL SQRLSnutS SQRLGuts™ ?
    tim is the author. Nov 21, 07:59 is the time. <
  2. Tim, if the “it” to which you refer is the code output by phpMyAdmin, then no, I don’t think so. The code fails to accomplish that goal, as it doesn’t even work in PHP/mySQL (an early place to fail in the attempt to be universal, since they’re doing so when interfacing with mySQL, the very database that phpMyAdmin focuses on).

    The most ironic part, perhaps, is that phpMyAdmin claims the code to be actual PHP code. To that, I say, “HA!”
    Nathan Logan is the author. Nov 21, 11:22 is the time. <
  3. are you using the export function from phpmyadmin?

    Do you mean that it’s missing the php $sql= statement?

    I think the export form the DB is straight SQL, and not intended to be PHP, but just SQL.

    I’ve used it, and i think the output is pretty standard:

    INSERT INTO `hettnuke_advanced_polls_data` VALUES (5, ‘Atari’, 8, ‘’);
    tim hettinger is the author. Nov 22, 15:16 is the time. <
  4. No, I’m using the Insert function in phpMyAdmin. When you click the “Generate PHP Code” (or something similar) button, it generates something that looks like this:

    INSERT INTO `TableName` (`ID`, `Name`, `Address`, `Phone`, `City`, `State`) VALUES (‘’, ‘Billy Bob’, ‘123 Main Street’, NULL, ‘New York’, ‘NY’)

    And that code never ceases to fail for me when I’m trying to insert from PHP into a mySQL database. Removing the errant ` marks seems to take care of it (and there may be some other slight changes, although I can’t remember at this moment).
    Nathan Logan is the author. Nov 25, 19:50 is the time. <
  5. oh, i didn’t even know it had ”’Generate PHP Code’ (or something similar) button.”

    i’ll make sure and not find it. :)
    tim is the author. Nov 28, 08:04 is the time. <