php - MySQL syntax to insert new rows based on mixed variables plus select records from another table -


question how write mysql statement combination of variables , data table.

for example, records in table contractor, want insert id , name contractor table renewals… plus add variables $foo , $bar columns foo , bar on same insert

$foo = 'foo'; $bar = 'bar'  insert renewals (id, name, foo, bar) select id, name contractor 

i'm drawing blank on how finish writing statement add $foo , $bar not coming table contractor each of new rows.

also, renewals has composite key based on (id, name, foo) need add

on duplicate key update bar = '$bar'  

at end of statement.

$query = "insert renewals (id, name, foo, bar) " . "select id, name, '$foo', '$bar' contractor " . "on duplicate key update bar = '$bar'"; 

it doesn't matter $foo , $bar don't come table contractor.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -