0

Hi i'm having difficulty passing in a value containing an ó into a SQL statement.

The while loop will not run due to the statement not running. The statement runs fine with any other values passed in except this particular one.

Is there a way I can encode the statement so that it runs?

I cannot change the ó for a normal o as the value in the database contains an ó.

The code I have been trying is below.

Cheers

<?php
include 'connect.php';

$choicetest = 'óvil';



$query = "SELECT test FROM [testtable] WHERE test = '$choicetest' GROUP BY test"; 
$result = sqlsrv_query($conn, $query);
while ($line = sqlsrv_fetch_array($result)) {


  $var = 'hello'; 

}

?>
1
  • Or use another collation when doing the comparison, one treating ó as o. Commented Sep 8, 2015 at 10:50

1 Answer 1

1

Make sure the table's default character set is UTF8. Then, before any queries, issue these:

SET NAMES utf8; SET CHARCTER SET utf8

Then your query should work as expected.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, is there a method around this if the database is in SQL_Latin1_General_CP1_CI_AS ? as i cannot change the collation due to read only access? cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.