0

so I have little problem, because I need to check if "product" exists in database, and if not, I want to create one. I was doing something like this:

$tekst2 = "SELECT * FROM product WHERE nazwa = '$nazwa'";
$id_zap2 = mysql_query($tekst2);
if(!$id_zap2)
{
    return new Response('Nie można przesłać zapytania.');
}
else
{
    $row2 = mysql_num_rows($id_zap2);
}

if($row2 == 0)      
{
    $product->setCena($cena);
    $product->setJednostka($jednostka);
    $product->setIlosc($ilosc);
    $product->setNazwa($nazwa);

    $em = $this->getDoctrine()->getManager();
    $em->persist($product);
    $em->flush();   

    return $this->redirect('addproduct?done=' . $nazwa);    
}   
else
{
    return $this->redirect('addproduct?error=1');   
}

And when I'm using for "$nazwa" normal letters all is ok. For example "Kukurydza", "Chleb" work fine, but when I use polish letters, for example "Mąka" it always returns 0 as "$row2" and I can create a lot of products with the same name ($nazwa).

Mateusz
  • 323
  • 2
  • 11
  • 23

1 Answers1

0

I hade to add:

$tekst3 = "SET NAMES utf8";
mysql_query($tekst3);
$tekst3 = "SET CHARACTER_SET utf8_unicode_ci";
mysql_query($tekst3);

In my code and now all works ok!

Mateusz
  • 323
  • 2
  • 11
  • 23