Feature Request: php insert and other statements

[expired user #7204]'s profile image [expired user #7204] posted 11 years ago in Feature discussion Permalink
Hello.

I was wondering if it could be possible to put on the table context menu a "php insert" statement that would put on the clipboard a php insert statement including all the fields (taking into consideration the field type string/numeric/boolean etc)
eg insert into database.table (field1,field2,field3...) VALUES ('',,''...)
or
insert into database.table (field1,field2,field3...) VALUES ($field1,$field2,$field3...)

You could make it more generic like making the menu "php statements" and SELECT,INSERT,DELETE,UPDATE
select select could select everything
eg
SELECT field1,field2,field3 FROM database.table
the DELETE and UPDATE statements could use there primary keys
eg DELETE from database.table WHERE _primarykey_=$key
UPDATE database.table SET field1='$field1',field2='$field2' WHERE _primarykey_=$key

i think it would be a great -easy to develop- feature for all php developers who require to do this several times per day.

Give it a though
ansgar's profile image ansgar posted 11 years ago Permalink
What the hell are "PHP inserts"?

Please see the "Export grid rows" dialog after rightclick on a query result, which offers "SQL INSERTs", "SQL REPLACEs" and "PHP array" already. Guess you want one of these.
[expired user #7204]'s profile image [expired user #7204] posted 11 years ago Permalink
I meant PHP *SQL* Insert

Something like that. But if the table is new and there are no rows available, you cannot use the Export grid dialog.

The results would be similar with the ones from the export grid dialog, except it would be filled with empty values or php variables
kalvaro's profile image kalvaro posted 11 years ago Permalink
Do you mean output like this?

$sql = 'INSERT INTO address (address_id, address, address2, district, city_id, postal_code, phone, last_update) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
$params = array(
'address_id' => null,
'address' => null,
'address2' => null,
'district' => null,
'city_id' => null,
'postal_code' => null,
'phone' => null,
'last_update' => null,
);


Honestly, it looks like an extremely specific use case to be worth the clutter.
[expired user #7204]'s profile image [expired user #7204] posted 11 years ago Permalink
Or something link this
$sql = "INSERT INTO address (address_id, address, address2, district, city_id, postal_code, phone, last_update) VALUES ($address_id, '$address', '$address2', '$district', $city_id, $postal_code, $phone, $last_update)";

I agree, for db admins it's pretty useless. But for web developers saves some valuable time and mental-breakdown for repeating the same procedure (view table properties, check type etc) several times in a project
ansgar's profile image ansgar posted 11 years ago Permalink
I now get you want a one-liner, not an exported set of values already contained in a table. That's what the right-click menu items in the very right query helpers box are for. Expand "Columns in table xy", then select wanted columns and rightclick them, click "Generate INSERT"
kalvaro's profile image kalvaro posted 11 years ago Permalink

Or something link this
$sql = "INSERT INTO address (address_id, address, address2, district, city_id, postal_code, phone, last_update) VALUES ($address_id, '$address', '$address2', '$district', $city_id, $postal_code, $phone, $last_update)";



So you're not interested in the variable definitions, just the SQL? That alright, it could be a useful feature to be able to get these:

INSERT INTO address (address_id, address, address2, district, city_id, postal_code, phone, last_update) VALUES (?, ?, ?, ?, ?, ?, ?, ?);
INSERT INTO address (address_id, address, address2, district, city_id, postal_code, phone, last_update) VALUES (:address_id, :address, :address2, :district, :city_id, :postal_code, :phone, :last_update);


... in addition to what HeidiSQL can already do:

INSERT INTO address
(address_id, address, address2, district, city_id, postal_code, phone, last_update)
VALUES (NULL, '', '', '', 0, '', '', NOW())


Please note that there's nothing PHP specific here, thus it's a great feature.

But the exact feature you suggest is basically only useful to PHP coders who don't want to use prepared statements and I can't help asking: why would anyone not want to use prepared statements?

Please login to leave a reply, or register at first.