Jump to content

Mysqli Support For Utf8


NurAzije
 Share

Recommended Posts

Hi all,I am trying to bind a non-Latin parameter in a prepare statement but I can not get it work, here is my code:

$db_connection = new mysqli("localhost", "user", "dbpass", "dbname");	$statement = $db_connection->prepare("SELECT sometext FROM pages WHERE url = ?");	$url = "čćšđž";	$statement->bind_param("s", $url);	$statement->execute();	$statement->bind_result($sometext);	$statement->fetch();	$statement->close();		print $sometext;

Even id I have this record in the DB, it returns me nothing. When I use the same query on phpMyAdmin it works.Can anyone help please?

Link to comment
Share on other sites

Might be easier to reconfigure your mysqli instance to accept all character sets

Link to comment
Share on other sites

You can set the client encoding to UTF-8 with mysqli::set_charset(). Note that for the $url to be read (and therefore added to the DB) correctly, your PHP file needs to be UTF-8 encoded as well. In Notepad, you can do that from the "Encoding" menu in the "Save as..." dialog.

Link to comment
Share on other sites

You can set the client encoding to UTF-8 with mysqli::set_charset(). Note that for the $url to be read (and therefore added to the DB) correctly, your PHP file needs to be UTF-8 encoded as well. In Notepad, you can do that from the "Encoding" menu in the "Save as..." dialog.
Hi,I have used mysqli::set_charset() and saved everything in UTF8 but still, when I use mysql it works fine, but with mysqli it does not. Any more ideas.Ashraf
Link to comment
Share on other sites

Your bindParam() call assigns "s" to the URL value. In other words, your full query becomes

SELECT sometext FROM pages WHERE url = 's'

If there are no results for this, you're logically going to get nothing. Try it like:

$statement->bind_param($url);

Link to comment
Share on other sites

I I use for example

$url = "hello";

it returns me results without any problems, just if I use any non-Latin characters it does not pass. I tried to save all data as urlencoded in the DB then before passing the parameter make it urlencoded but that did not work also ??Any idea's, I do not want to get back to mysql extension and work with all the security holes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...