I am having issues displaying data from MySQL in datatables(.net) containing Norwegian characters (Æ, Ø, Å, etc.). I'm running CodeIgniter and have the following variables configured in database.php:
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
I am also using utf8_encode on data from forms before inserting it into the database, but when I extract the data thing gets displayed. The database is also configured with utf8_general_ci. In short my question is: how should I configure CodeIgniter and MySQL to be able to both insert and extract data from the database without issues ? Should I use utf8_encode before submitting the data or is that just double encoding and a part of the issue ?
PS! I don't think datatables are part of the problem since the field is already empty when data gets sent to the datatables.
PS2! I'm not sure why, but I'm only facing issues with uppercase norwegian letters. Ø fails to display, but ø work fine. Å fails to display, but å works fine.
I had a similar problem last week & I figured out that it wasn’t the DB that had problem but it was the way the Codeigniter transacts the data.
So every time before saving the data in the database, I pass the data through
htmlentities($str, ENT_QUOTES | ENT_HTML401, "UTF-8");
And before showing the data in html, I again pass it through
html_entity_decode($str, ENT_COMPAT | ENT_HTML401, 'UTF-8')
Just for record, I have this in my DB Config file
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
Try to use this:
mysql_select_db('db_name');
mysql_query("SET NAMES 'utf8'");
Put mysql_query("SET NAMES 'utf8'"); after select database line
Related
I am working on an Arabic-French lexicon.
https://lexique-arabe.org
Using the latest version of Codeigniter (3.1.10).
I haven't a problem to save and view Arabic characters, AJAX requests for Arabic characters work fine.
But, I try to create mixed slug for an Arabic-French lexicon.
For example I need to create
lexique-arabe.org/lexique/amour-محبة (this link doesn't exist yet.)
I use url_title to generate the slug
Helper
function setSlug($string){
$string = convert_accented_characters($string);
return url_title($string, 'dash', true);
}
Controller
$string = $mot->fr.' '.$mot->ar;
$slug = $this->db_utils_lib->stripAccents(setSlug($string));
Result in the database for the field slug :
amour-????????
The ???????? should be the Arabic characters.
If you check the website, you can see that there is no problem with the Arabic characters to save are in the database.
I think there is a problem with config or url_title function
My database config
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
Some config
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
Can someone help me?
Thanks
Patrice
Make sure your database encoding accept arabic.
Using SQL and database management tool. Try create a table with text column.
Try to insert Arabic text into the database.
Make sure the text is stored as Arabic.
Try different database clients to see the Arabic text data. Sometime the data is correct but the client/browser/GUI fails to render the correct encoding.
Or simply the client/browser/GUI is missing the correct font.
I have started using the Dhtmlx Scheduler a few days ago, i went to the docs to see how to create a simple connection and load some data but i keep getting this: { "data":[]} has the response of my .php file. My code is:
<?php
include('connector-php/codebase/scheduler_connector.php');
$pdo=mysqli_connect("localhost","root","pass","hotel");
$scheduler = new JSONSchedulerConnector($pdo);
$scheduler->render_table("TipoQuarto","idTipoQuarto","Nome,Preco");
echo scheduler;
?>
For now i´m just working on the .php file to see if the connector can find my data, and i know there is data there. My database has several tables, so i´m selecting the TipoQuarto, then the id of the field(idTipoQuarto) and then the fields i need, but it´s not displaying anything. Can anyone help me?
Regards.
For MySQLi server side code will look like next
require("connector/scheduler_connector.php");
require("connector/db_mysqli.php");
$mysqli =mysqli_connect("localhost","root","pass","hotel");
$scheduler = new JSONSchedulerConnector($mysqli, "MySQLi");
$scheduler->render_table("TipoQuarto","idTipoQuarto","Nome,Preco");
you need to include db_mysqli.php
second parameter of constructor must be "MySQLi"
Also, in render table, third paremeter mast include start date, end date and text fields. You are providing only two of them.
I am trying to find a way to run codeigniter from a sub-directory of another codeigniter installation. The CI from the sub-directory would be for testing and the main one is the live site. Anyone could advice on this or any other better approach ?
I believe you can just place this in the root folder and set the base url in the config :
$config['base_url'] = 'http://www.example.com/testsite/';
then it works.
There can be issues with the first application serving the 404 pages when a route is not matched however
I am posting the answer here, because is too long to use it as a comment...
I made it thru another approach: setting different $active_group in the config/database.php file.
So, first I have checked for a parameter in $_GET, if that is set we use a group, otherwise the default group (the other group is used for testing - a separate database, exact structure but without touching the main db)
if(!isset($_SESSION)){session_start();}
if (isset($_GET["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
$_SESSION['debugmode'] = true;
}elseif (isset($_SESSION["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
}elseif(!isset($_GET["debugmode"]) && !isset($_SESSION["debugmode"])){
$active_group = 'default';
$active_record = TRUE;
}
To make sure this will work on all the controllers /views, because we wont have that $_GET parameter all over the application, we can set that session value once we have that $_GET parameter present. Also, we have to make sure we destroy that session when we log out or after an amount of time.
Reason of using a Session value: by default CI is using that table to store the sessions, without using our session value, it will force somehow to use the default DB, or at least I couldn't find it to trick this step.
Hi has anyone had experience with using AES_DECRYPT and codeigniters active record. I've tried using the following line:
$query = $this->db->select("AES_DECRYPT(testing,'$key') as testing");
but continue to get an sql syntax error. I've tried using a manual standard sql string which works but would prefer to stick with active record if I can.
CodeIgniter is trying to escape that, and it has no idea how to. Add FALSE as the 2nd parameter to tell it not to escape it.
// We need to escape this value before the query
$key = $this->db->escape($key);
// Tell CodeIgniter not to escape this
$this->db->select("AES_DECRYPT(testing, $key) as testing", FALSE);
I'm very new to php and mysql. I'm trying to pass the value "part(2)" to my code igniter controller. "part(2)" is one of the name of the data values in my database. After passing it to the uri segment, I extracted it using the command $value = str_replace("%20", " ", $this->uri->segment(5)); . Now when i search my database using the variable $value, it's not displaying the results. I presume the problem is with having using "()". I am wondering if it has anything to do with the data type utl8 vs latin1. My database is configured to use latin1_general_ci. I have tried changing the database field type to utl8_general_ci, but it does not work. Can anyone please help me out here?.
Have you tried var_dump($value) just to see what it contains?
Also, the result from $this->db->last_query(); might be useful to see what you are actually quering your database for. I don't see a reason why you couldn't put perenthesis in your database.
Im pretty sure both utf8 and latin1 are fine.
can you post your controller code?
firstly, if you are passing the value in your uri, do you have () in your permitted uri characters in application/config/config.php?
something like this:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-()';
But I just tried this and my values came out with html entities: part(2) instead..
you can fix this with something like this:
input_value = html_entity_decode($input_value);