Maaren Posted June 17, 2008 Report Share Posted June 17, 2008 Kā lai iebāž divas komandas vienā querijā? rakstu mysql_query("insert into userlist(user,password,mail,sex,level,name,surname) values('$username','$dbpass','$mail','$sex','1','$firstname','$surname') AND delete * from inactive_user WHERE id='$inactiveid"); raksta man You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete * from inactive_user WHERE id='32' at line 1 Kā lai pareizi uzraksta? Link to comment Share on other sites More sharing options...
Ghenis Posted June 17, 2008 Report Share Posted June 17, 2008 uzraksti procedūru vai iebāz ; pa vidu. Link to comment Share on other sites More sharing options...
Maaren Posted June 17, 2008 Author Report Share Posted June 17, 2008 īsti nesapratu tavu atbildi.. Link to comment Share on other sites More sharing options...
andrisp Posted June 17, 2008 Report Share Posted June 17, 2008 Ja izmantotu mysqli_query (php.net/mysqli), tad vareetu kverijus atdaliit ar semikolu (;). Vai arii izveodu proceduuru, kurai padosi vajadziigos parametrus un kura izsauks vajadziigos kverijus. A kur probleema divreiz izsaukt mysql_query() ? Link to comment Share on other sites More sharing options...
Maaren Posted June 17, 2008 Author Report Share Posted June 17, 2008 Gribēju vnk. iemest vienā querijā, laikam manu paranoisko iedomu dēļ.. :) Doma bija tāda, ka pie lietotaaja aktivizaacijas, lietotaaja dati tiek paarvietoti uz aktiivo useru tablu un no neaktiivo tiek dzeesti.. Bailes, ka kaadreiz viens no querijiem var nenostraadaat, tad sanaaks taa, ka lietotaajs vai nu nebuus ne vienaa no tabulaam, vai arii abaas.. Link to comment Share on other sites More sharing options...
black Posted June 17, 2008 Report Share Posted June 17, 2008 Liec abus vienā transakcijā. Link to comment Share on other sites More sharing options...
Klez Posted June 18, 2008 Report Share Posted June 18, 2008 if (izpildaas_query1()) izpildaam_query2(); else echo 'query1 failed ..'; palasi manuaali par mysql_query() Link to comment Share on other sites More sharing options...
andrisp Posted June 18, 2008 Report Share Posted June 18, 2008 black, MyISAM tabulas transakcijas neatbalsta. Tad būtu jāizmanto InnoDB. Domāju, ka šajā situācijā Klez variants ir vislabākais. Link to comment Share on other sites More sharing options...
codez Posted June 18, 2008 Report Share Posted June 18, 2008 Lieto InnoDB, foreign keys arī ir vajadzīga un noderīga lieta. Link to comment Share on other sites More sharing options...
Maaren Posted June 18, 2008 Author Report Share Posted June 18, 2008 Klez, es labi pārzinu mysql_querijus, tikai interisēja par 2 komandām vienā querijā.. Es tā kā tu arī izdarīju un vienmēr esmu darijis.. if (izpildaas_query1()) izpildaam_query2(); else echo 'query1 failed ..'; bet baidos es jau par to, ja izpildiisies pirmais querijs un neizpildiisies otrais.. tur taa lieta.. Link to comment Share on other sites More sharing options...
andrisp Posted June 18, 2008 Report Share Posted June 18, 2008 Maareen, ja tas tiešām ir tik ļoti svarīgi (un nevari/neveelies izmantot InnoDB tabulas, kas nodrošina transakcijas), tad taisi šitā: 1. Veic insertu 2. Ja viss Ok turpinam. 3. Dabū insertā ģenerēto ID. 4. Veicam delete. 5. Ja delete == false, izdzēšam pirmajā kverijā insertoto rindu (mums ir ID). Link to comment Share on other sites More sharing options...
black Posted June 18, 2008 Report Share Posted June 18, 2008 Vai tad viņš kaut kur saka, ka viņš izmanto MyISAM? Link to comment Share on other sites More sharing options...
andrisp Posted June 18, 2008 Report Share Posted June 18, 2008 black, neviens jau arī neapgalvo, ka viņš saka. :) Link to comment Share on other sites More sharing options...
Aleksejs Posted June 18, 2008 Report Share Posted June 18, 2008 Maaren, ja ir tik ļoti svarīgi, lai izpildās abas divai vai neviena, tad transakcijas (ar visu no tā izrietošo) ir vissaprātīgākā izvēle. Link to comment Share on other sites More sharing options...
Klez Posted June 18, 2008 Report Share Posted June 18, 2008 (edited) mazlet pielabojam ... if (izpildaas_query1()) { $id = mysql_query_id(); if (izpildaam_query2()) { echo "viss bumbaas"; }else { dzesham_no_mysql($id); echo "galiigi garaam"; } }else echo 'query1 failed ..'; Edited June 18, 2008 by Klez Link to comment Share on other sites More sharing options...
Recommended Posts