homepage Welcome to WebmasterWorld Guest from 54.166.113.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Options for inserting and updating mysql
Options for inserting and updating mysql
drooh

5+ Year Member



 
Msg#: 4331051 posted 6:34 pm on Jun 25, 2011 (gmt 0)

Is it possible to do something like this?

$sql = "UPDATE `test` SET (`name`,`age`) VALUES ('Sam','34') WHERE `id` = 10";

It would be nice because the insert command is similar

$sql = "INSERT INTO `test` (`name`,`age`) VALUES ('Sam','34')";

 

drooh

5+ Year Member



 
Msg#: 4331051 posted 6:37 pm on Jun 25, 2011 (gmt 0)

Or vise versa, is there a way to

$sql = "INSERT INTO `test` (`name`='sam',`age`='34')";

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4331051 posted 8:10 pm on Jul 5, 2011 (gmt 0)

Have you checked the optional syntax?
[dev.mysql.com...]

drooh

5+ Year Member



 
Msg#: 4331051 posted 8:51 pm on Jul 5, 2011 (gmt 0)

not really seeing an answer there? Can you specify some code or be more specific?

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4331051 posted 9:06 pm on Jul 5, 2011 (gmt 0)

Second syntax example is almost exactly what you typed in your second post ...

INSERT INTO test SET name = 'sam', age = 34;
drooh

5+ Year Member



 
Msg#: 4331051 posted 9:35 pm on Jul 5, 2011 (gmt 0)

Ok, thank you, I wish they could write their examples like that. For some reason that mysql website is just so hard for me to read.

Somehow

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE
col_name=expr
[, col_name=expr] ... ]

Just doesnt register in my brain.

thanks for you post and letting me know this is possible.

drooh

5+ Year Member



 
Msg#: 4331051 posted 11:04 pm on Jul 5, 2011 (gmt 0)

This was exactly what I was looking for, this way I can re-use a portion of the query for inserting and updating.

Just out of curiosity at this point, is there a way to do something like this?

$sql = "UPDATE `test` SET
(
`name`,
`age`
)
VALUES
(
'Pete',
'34'
)
WHERE `id` = 10
";

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4331051 posted 12:32 pm on Jul 7, 2011 (gmt 0)

not according to the syntax ...
[dev.mysql.com...]

Regarding reading the manuals and understanding the syntax ...
[dev.mysql.com...]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved