1

I was given an sql database that I was supposed to do some stuff on, and I want to clean it up, given that they have stuff with "special characters" as values, such as carcaças. Notice the `ç.

My Update command just simply doesn't want to work. I've checked in a million times and the weird part is on the webservice that I'm creating using that database the line seems to do nothing, but when I go on phpmyadmin it works perfectly. It has nothing to do with permissions given that its all being hosted on my computer.

So here you go the code:

function filter($stockconn){
    mysqli_query($stockconn,"UPDATE produtos SET familiaprod='Carcacas' WHERE familiaprod='Carcaças'") or die(mysql_error());
    mysqli_close($stockconn);
}

So far its all very simple, simple connection file (which is working correctly 100%) being pulled towards that function.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • 2
    For one thing, change `die(mysql_error()` to `die(mysqli_error($stockconn)` – Funk Forty Niner Jul 03 '14 at 13:44
  • Plus, `carcaças` may not be the same as `Carcaças` with the uppercase `C` should that be the case. – Funk Forty Niner Jul 03 '14 at 13:46
  • Oh ye i forgot i was using mysqli, yep changed and still no outputed error message. – user3801902 Jul 03 '14 at 13:47
  • 1
    What matters here is your table or column's [collation](http://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html), which will determine whether `Carcacas` is treated the same or differently from `Carcaças` – Michael Berkowski Jul 03 '14 at 13:48
  • Do you have multiple records containing that string, or just one row? – Funk Forty Niner Jul 03 '14 at 13:48
  • Ye fred but the thing is, if that was the case when i tried it on phpmyadmin it wouldn't have worked but it did, which shows the problem is with this outter syntax or something :S – user3801902 Jul 03 '14 at 13:49
  • carcaça is a product "category" so i have multiple rows with that string. – user3801902 Jul 03 '14 at 13:50
  • Add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` see if it yields anything. As for multiple rows, that one I don't know how to update "all" rows containing a particular string, but am sure I'd find a way to do it. – Funk Forty Niner Jul 03 '14 at 13:51
  • This will probably help http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Mihai Jul 03 '14 at 13:52
  • Tried adding that to no result, the thing is, when i run that command on phpmyadmin it works fine, updates all the rows etc etc, what is really weird is that when i run it on the webservice/website it does nothing, even tried isolating the code, to no result. – user3801902 Jul 03 '14 at 13:53
  • See this answer http://stackoverflow.com/a/4271225/ I think you need `REPLACE` – Funk Forty Niner Jul 03 '14 at 13:54
  • @davidsbro, I think you should have rejected that edit. There was much more the editor could have done. – gunr2171 Jul 03 '14 at 13:54
  • 1
    Alright guys i have the solution, i was a bit suspicious it had something to do with the charset, and indeed it had, i had tried giving the document diferent charsets but it didnt work, altho with the link provided by @Mihai i ended up setting the database's charset to utf8mb4 and it changed rows sucessfully, tyvm for all the help. function filter($stockconn, $opencartconn){ mysqli_set_charset($stockconn, 'utf8mb4'); mysqli_query($stockconn,"UPDATE produtos SET familiaprod='Carcacas' WHERE familiaprod='Carcaças'") or die(mysqli_error()); mysqli_close($stockconn); } – user3801902 Jul 03 '14 at 14:04
  • 1
    Post it as an answer and accept it. – Mihai Jul 03 '14 at 14:05
  • Great, glad to hear it. `Another happy ending` ;-) – Funk Forty Niner Jul 03 '14 at 14:12
  • @gunr2171, I agree completely; however, it was already approved by three other editors, so I just decided to fix a couple obvious things. But I completely agree; some reviewers seem to approve everything (like a 20 to 1 approve/reject ratio). I normally would reject an edit like that. I think there are too many robo-reviewers...http://stackoverflow.com/review/suggested-edits/5213908 – davidsbro Jul 03 '14 at 17:00

0 Answers0