Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
NickD
- Pro Scripter
- Posts: 58
- Joined: Fri Sep 23, 2016 2:17 pm
Post
by NickD » Mon Aug 28, 2017 11:27 pm
The script I am working on stores a MYSQL database in an array, then loops through the rows looking for rows that have a specific value in one field:
Code: Select all
// MySQL Database To Array
Let>SQL=SELECT * FROM %MySQLtable%
DBConnect>Driver={%ODBCDriver%};Server=%DBServerIP%;Port=%DBPort%;Database=%DBName%;User=%DBUser%;Password=%DBPass%;Option=3;,dbH
DBQuery>dbH,SQL,Post,numRecs,numFields
DBCLOSE>dbH
// Check If Already Published
Let>row=0
Label>NextRow
Repeat>row
Let>field=16
Let>row=row+1
Let>this_field=Post_%row%_%field%
If>%this_field%<>Yes
Goto>PostThis
Endif
Until>row=numRecs
My question is how would I then go about updating the MySQL database to insert a new value in field 16 on the selected row?
I need to do this without affecting the other fields on that row.
There does not seem to be much info published on how to use DBExec with the UPDATE query either in the forums or in the help files.
Thanks.
-
NickD
- Pro Scripter
- Posts: 58
- Joined: Fri Sep 23, 2016 2:17 pm
Post
by NickD » Tue Aug 29, 2017 11:41 am
Cracked it!
For anyone else searching for how to do this, try
Code: Select all
Let>SQLCmd=UPDATE %MySQLtable% SET Field1='Value1',Field2='Value2' WHERE id=%autoincrement_row_id%
DBConnect>Driver{%ODBCDriver%};Server=%DBServerIP%;Port=%DBPort%;Database=%DBName%;User=%DBUser%;Password=%DBPass%;Option=3;,dbH
DBExec>dbH,SQLCmd,SQLReport
DBCLOSE>dbH