Programming

32 articles

Turn PHP_SESSID off on an OVH shared server

In a .htaccess file, add:

SetEnv SESSION_USE_TRANS_SID 0

In your PHP code:

ini_set('session.use_cookies', '1');
ini_set('session.use_only_cookies', '1');  // PHP >= 4.3
ini_set('session.use_trans_sid', '0');
ini_set('url_rewriter.tags', '');

MySQL: dump the encoding hell

I have encountered this issue in MySQL version 5.1.x, but not in 5.5 (I have not tested other versions): generating a dump of a UTF-8 encoded database (Collation: utf8_general_ci) resulted on non-ASCII characters (like "éà ç") being garbled.

I am used to backup databases with this mysqldump command:

$ mysqldump -h hostname -u username -p databaseName > backup.sql

I never had to worry about encoding since I use UTF-8 everywhere. But when I tried to import a dump file from 5.1 to 5.5, there were weird symbols like àƒ© àƒ§ all over the place! A workaround is to dump the database using the latin1 charset:

$ mysqldump -h hostname -u username -p --default-character-set=latin1 --databases databaseName -r backup.sql

The -r option outputs the data directly into backup.sql, avoiding risks of additional encoding interferences while passing through the underlying system.

Before importing the data, edit the dump file to replace the line

/*!40101 SET NAMES latin1 */;

with

/*!40101 SET NAMES utf8 */;

Finally import the dump file:

$ mysql -u username -p --default-character-set=utf8 databaseName

Source

MariaDB (MySQL): retrieve database collation

In the MySQL prompt:

> SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'databaseName' LIMIT 1;
+------------------------+
| DEFAULT_COLLATION_NAME |
+------------------------+
| utf8_general_ci        |
+------------------------+

Git: push a tag when the remote is up-to-date

I started using tags a few weeks ago, after reading "A successful Git branching model".

Update: tags are not pushed along without the --tags option. Tags are simply pushed along with the usual git push command. However, if a tag is created after pushing the latest commit, another git push just ignores it. To explicitly tell Git to push a tag called tagName:

$ git push origin tagName

The following command push all the tags:

$ git push --tags

Source

Git: push/pull new branches to/from a remote repository

To push the branch newbranch to the remote repository origin:

$ git push -u origin newbranch

The -u option (we can also use the more verbose --set-upstream option) tells Git to also track this branch, thus allowing us to pull automatically future upstream commits using git pull.

To pull the branch newbranch from a remote repository origin, we first update our local repository:

$ git fetch origin

Then we create a local branch called newbranch and set it to track the upstream one:

$ git checkout --track origin/newbranch