I was trying to update approx 20,000 records in a table by using statements like this one,
however, I got the message say 0 row(s) affected
so it didn\'t work.<
was looking for same but didn't work for me.... but this works perfect:
$title = "Worklog details";
$log_name = 'PC01';
$update = $connection -> prepare("UPDATE nc_files
SET title = ?
WHERE log_name = ?");
$update->bind_param('ss',$title,$log_name);
$update->execute();
$update->close();
I had a similar trouble. The problem are the quotations marks " I Fixed my code as follow.
UPDATE Table SET Table.Field = "myreplace" WHERE (((Table.Field) Like '%A-16%'));
Regards, Alexwin1982
"log_name" should not be in quotes
By default MySQL allows double quoted names to be understood as either identifiers (like column names) or as string literals.
This is meant as a convenience, but I find the semantic ambiguity frustrating. MySQL must resolve the ambiguity, and cannot magically always guess the coder's intention, as you discovered.
-- In default sql_mode under 5.5
--
SELECT "foo" -- "foo" is a *column* if tbl.foo exists, otherwise a string
FROM "tbl" -- Oops! ER_PARSE_ERROR (1064) Can't do this in default mode.
WHERE "foo" = "foo"; -- Both of these are strings
So, the way around it is to force unambiguous interpretation of identifiers:
sql_mode
to include ANSI_QUOTES (or a superset of it)#3 is my personal favorite, for readability and portability. The problem is it tends to surprise people who only know MySQL, and you have to remember to override the default.
this is because your column name log_name
should not be in '
quotes.
"log_name" LIKE "%PC01%"
condition will always fail and zero rows will get updated, try this:
UPDATE nc_files
SET title ="Worklog details"
WHERE log_name LIKE "%PC01%";
The log_name
is a field name, remove literal quotes from it -
UPDATE nc_files SET title ="Worklog details" WHERE log_name LIKE "%PC01%"