php - Insert into table and return the Auto Increment Id Assigned -
i inserting information cars, in 3 different instances, in first goes auto containing 4 rows basic year make model , price , unique id set automatically mysql. great. how return id set instance can use insert other 2 instances of pictures , attributes?
$toauto = "insert auto(year, make, model, mileage, price) values (?, ?, ?, ?, ?)"; /* //sql inserting auto $toattributes = "insert attributes(auto_id, bodystyle, enginesize, cyl, hp, fuel, transmission, shifts, od, cd, mp3, dvd, gps, sound_system, sradio, tachometer, clock, trip, eweather, digitalboard, rwd, fwd, awd, fxf, cruisecontrol, tiltsteering, ac, removabletop, keyless, airbags, alloy, trunkantitrap, ewindows, emirrors, eseat, elocks, antitheft, leadheadlights ) values ($autoid, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; //sql insert pictures $topictures = "insert auto(year, make, model, mileage, price) values (?, ?, ?, ?, ?)"; */ print_r($auto); print_r($paths); //$dbh->setattribute( pdo::attr_errmode, pdo::errmode_exception ); //inserting auto $sth = $dbh->prepare($toauto); $final = array_merge(array_values($auto)); $sth->execute($final); /* //inserting attributes $sth = $dbh->prepare($toauto); $final = array_merge(array_values($auto)); $sth->execute($final); //inserting pictures $sth = $dbh->prepare($toauto); $final = array_merge(array_values($auto)); $sth->execute($final); */
the row name auto_id
assuming using pdo, call $dbh->lastinsertid()
auto increment id last insert operation.
Comments
Post a Comment