Fruml CMS Community: PDO to use correct UTF - Fruml CMS Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PDO to use correct UTF

#1 User is offline   Far Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 04-February 10

Posted 10 February 2010 - 01:50 PM

When Immerse appeared there was a problem with charsets difference in different languages. I got problem with backups of the DB, when non-utf characters were lost in the process. The same problem still here. PDO shall set utf-8 as default.

Please add to class/class.db.php file after the line 38($this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);) a new command :

$this->db->exec("set names utf8");


It will help people using non-latin languages have correct utf-8 characters in the DB. So there will be no problem with backuping and restoring of the DB.
0

#2 User is offline   Alex Icon

  • Author
  • Icon
  • Group: Administrators
  • Posts: 56
  • Joined: 17-January 10

Posted 10 February 2010 - 02:20 PM

Done!

Just pushed it to the Mercurial repo at BitBucket.

I tested it, it seems to work fine (although existing Cyrillic characters were corrupted, new characters are stored correctly).
0

#3 User is offline   Far Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 04-February 10

Posted 18 February 2010 - 01:14 PM

I got one question about database. The DB class is very easy and powerfull. But before i did not use PDO at all. Shall we escape entries in sql query, before run the query. Or PDO do it automatically?

e.g. Is this sql safe?
<?php
$sql = 'SELECT * FROM %tp%action WHERE controller = '.CONTROLLER;
$rs = $db->query($sql)->fetchAll();

In the cms there is no routing for url and also there is no escaping for the data passed through the url, so the data from url gets to the script in raw format and can contain some sql injections. But the question is not about the data it self, does the PDO escapes variables in sql?
0

#4 User is offline   Alex Icon

  • Author
  • Icon
  • Group: Administrators
  • Posts: 56
  • Joined: 17-January 10

Posted 18 February 2010 - 01:43 PM

PDO automatically escapes data passed to it for queries written like this:
<?php
DB::getInstance()->query("SELECT * FROM %tp%action WHERE controller = ?", CONTROLLER);
?>


If you place the variables in your query yourself (like you show above) then you have to addslashes() it first.

There is some routing, namely:

/[cms]/[controller]/[action]/[REQUEST]

[controller] decides which Controller is loaded (in action/controller.***.php)
[action] decides which method is called on the controller.
[REQUEST] is explode()'d using the / character and the results are passed to the [action] as paramters.

So...

/cms/template/edit/2

will load the TemplateController in actions/controller.template.php, and then call the edit function and pass 2 as the first argument: TemplateController->edit(2);

The arguments passed to the methods are not escaped, that should be done by the code in the function itself (or the db functions).

The only exception is when you call a URL without /cms/ in front of it. Those are all passed to the FrontController, which parses the URL and decides which page should be displayed.
0

#5 User is offline   Far Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 04-February 10

Posted 18 February 2010 - 07:55 PM

If there were any kind of controllable router(like in codeigniter) in fruml, it would be a good framework for developers, i guess.
0

#6 User is offline   Alex Icon

  • Author
  • Icon
  • Group: Administrators
  • Posts: 56
  • Joined: 17-January 10

Posted 18 February 2010 - 09:49 PM

Something like that should be possible, and might be a nice feature to add at some point.
First I want to concentrate on getting all the CMS bis finished first though. Maybe once that's pretty much done, we can think about Fruml as a framework as well as a cms.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users