Jump to content
php.lv forumi

mysql_query - transaction


goleh1995

Recommended Posts

Sveiks - varat man ludzu pastastit kas te ir nepareizi un ka izlabot.

$query = 'SET AUTOCOMMIT=0;
START TRANSACTION;
LOCK TABLES zr_zinojumi WRITE, tmptable WRITE;
CREATE TEMPORARY TABLE tmptable SELECT * FROM zr_zinojumi WHERE RZNM_ID='.$messageId.';
UPDATE tmptable SET RZNM_RPRJ_ID='.$izv.' WHERE RZNM_ID='.$messageId.';
INSERT INTO zr_zinojumi SELECT * FROM tmptable WHERE RZNM_ID='.$messageId.';
DROP TEMPORARY TABLE IF EXIST tmptable;
UNLOCK TABLES;
COMMIT;
';
mysql_query($query);	

 

Link to comment
Share on other sites

				mysql_query('SET AUTOCOMMIT=0;');
				mysql_query('START TRANSACTION;');
				mysql_query('LOCK TABLES zr_zinojumi WRITE, tmptable WRITE;');
				mysql_query('CREATE TEMPORARY TABLE tmptable SELECT * FROM zr_zinojumi WHERE RZNM_ID='.$messageId.';');
				mysql_query('UPDATE tmptable SET RZNM_RPRJ_ID='.$izv.' WHERE RZNM_ID='.$messageId.';');
				mysql_query('INSERT INTO zr_zinojumi SELECT * FROM tmptable WHERE RZNM_ID='.$messageId.';');
				mysql_query('DROP TEMPORARY TABLE IF EXIST tmptable;');
				mysql_query('UNLOCK TABLES;');
				mysql_query('COMMIT;');

Ari nestrada

Link to comment
Share on other sites

izmantot tmp tabulas parasati skaitās evil un pēdējais ko darīt.

m$sql var šādi:

 

insert into TableName(field1, field2, field3)
select
     field1,
     'izmainītā lauka vērtība' as field2,
     field3     
from TableName
where ..

varbūt mysql ar tā darbojas vai kā līdzīgi (nav pie rokas lai pārbaudīt)

Link to comment
Share on other sites

CREATE TEMPORARY TABLE tmptable SELECT * FROM zr_zinojumi WHERE RZNM_ID='3594';
UPDATE tmptable SET RZNM_RPRJ_ID='60', RZNM_ID='8000' WHERE RZNM_ID='3594';
select * into zr_zinojumi from tmptable Where RZNM_RPRJ_ID='60' ;

te es to ID izmainiju pie UPDATE  tagad itka jastarad, bet atkal.

#1064 - 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 'zr_zinojumi from tmptable Where RZNM_RPRJ_ID = '60'  LIMIT 0, 30

Link to comment
Share on other sites


mysql_query('CREATE TEMPORARY TABLE tmptable SELECT * FROM zr_zinojumi WHERE RZNM_ID='.$messageId.';');

mysql_query('UPDATE tmptable SET RZNM_RPRJ_ID='.$izv.', RZNM_ID='.$id.' WHERE RZNM_ID='.$messageId.';');

mysql_query('INSERT INTO zr_zinojumi(`RZNM_ID`,`RZNM_IDENTIFIKATORS`,RZNM_KRFK_ZIN_VEIDS,RZNM_KRFK_PRIORITAT,RZNM_KRFK_SNIEG_VEIDS,RZNM_KRFK_SMAGUMS,RZNM_ISS_APRAKSTS,RZNM_APRAKSTS,RZNM_NUMURS,RZNM_SASK_DATUMS,RZNM_PLAN_IZP_DATUMS,RZNM_PRASIBA,RZNM_NOVERTEJUMS_STUNDAS,RZNM_RPRJ_ID,RZNM_RZNM_ID_DUBLICE,RZNM_RZNM_ID_AIZVER,RZNM_RKLN_ID,RZNM_RVNM_ID,RZNM_RVVR_ID,RZNM_RVVR_ID_JAIEVIES,RZNM_RVVR_ID_IEVIESTS,RZNM_RLTT_ID_INS,RZNM_RLTT_ID_UPD,RZNM_DATUMS_INS,RZNM_DATUMS_UPD,RZNM_KSTV_KODS) SELECT

RZNM_ID,

RZNM_IDENTIFIKATORS,

RZNM_KRFK_ZIN_VEIDS,

RZNM_KRFK_PRIORITAT,

RZNM_KRFK_SNIEG_VEIDS,

RZNM_KRFK_SMAGUMS,

RZNM_ISS_APRAKSTS,

RZNM_APRAKSTS,

RZNM_NUMURS,

RZNM_SASK_DATUMS,

RZNM_PLAN_IZP_DATUMS,

RZNM_PRASIBA,

RZNM_NOVERTEJUMS_STUNDAS,

RZNM_RPRJ_ID,

RZNM_RZNM_ID_DUBLICE,

RZNM_RZNM_ID_AIZVER,

RZNM_RKLN_ID,

RZNM_RVNM_ID,

RZNM_RVVR_ID,

RZNM_RVVR_ID_JAIEVIES,

RZNM_RVVR_ID_IEVIESTS,

RZNM_RLTT_ID_INS,

RZNM_RLTT_ID_UPD,

RZNM_DATUMS_INS,

RZNM_DATUMS_UPD,

RZNM_KSTV_KODS

FROM tmptable WHERE RZNM_RPRJ_ID='.$izv.';');

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...