MySQL/PHP character encoding errors (e.g. æ,ø,å) – import, connection, table encoding and html meta header

Today I’ve got four hints that usually solves the character encoding errors I encounter with MySQL and PHP (usually triggered by the special Danish vowels æ,ø,å):

  • PhpMyAdmin import: use the official import function rather than executing crude sql inserts – because then you can specify the character encoding instead of using the default one which is NOT UTF-8.
  • Set encoding for PHP-MySQL connection: Here is an example:
    $conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');

    Link to reference.

    If you use the (much better) PDO db access layer, then you can just add an argument to the connection call:
    $conn = new PDO('mysql:host=' . $hostname . ';dbname=' . $dbname, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

  • Make sure that the MySQL database and tables are UTF-8 encoded: Use the following SQL-commands:
    ALTER DATABASE db_name
    COLLATE utf8_general_ci
    DEFAULT COLLATE utf8_general_ci;

    ALTER TABLE tbl_name
    COLLATE utf8_general_ci;

  • (x)HTML meta header character encoding: add this in the head section of the HTML code:
    <meta http-equiv="Content-type" value="text/html; charset=UTF-8" />

If you have got a question or more tips then please post it below, then I will update my post 🙂

Gnome Nautilus bookmarks/favorites backup (in Ubuntu)

Nautilus (default file manager in Ubuntu) saves bookmarks/favorites in the following file in the home folder:
~/.gtk-bookmarks or home/YOUR_USERNAME/.gtk-bookmarks

You might need to make hidden files (those that starts with a .) visible by pressing CTRL+H in Nautilus in order to find the file.

Just copy the file to another location to make a backup of it 🙂

False Science: The Comparative Anatomy of Eating by M.D. Milton R. Mills

I am not an expert on the topics “diets”, “anatomy” and “evolution” – but still I know how real science works and hence I can discard false science such as the article “The Comparative Anatomy of Eating” by M.D. Milton R. Mills. Creationists (Intelligent Design) have also created many such articles that claims to be scientific research – but real scientists can easily spot that they are wrong. There is no scientific evidence to support the hypothesis “human are herbivores”, so please stop corrupting the real science by spreading false science such as the article by M.D. Milton R. Mills. That is just vegan propaganda:

  1. No recognised scientific institution has published the article into e.g. a scientific journal – i.e. no significant body of experts believes that it is correct.
  2. As the article is not published in a scientific journal, no one has spent time to do a proper scientific peer review on it. In other words: no group of scientists has thoroughly checked whether it’s claims are justified.
  3. There are no references to existing publications and no are experiments conducted – i.e. it is neither based on existing research nor on creating new research. So there is no evidence to prove its claims.

This alone should be enough to stop believing that the article is science.

However, if we really need more dirty details, then a background check on the author reveals that: 1) he is not an expert on the topic and 2) he is biased by being involved with pro-vegetarian organisations.
1) The author is M.D. (from Stanford University link), but that only makes him a doctor, not an expert on this particular topic. I have tried to look for research conducted by him, but neither Google, Google Scholar nor PubMed yielded any relevant results. (Only pubMed actually had an article from him and that was not relevant: PubMed publication) Without having published any relevant research on the topic, M.D. Milton R. Mills is not an expert on the topic – in fact he just works as an outpatient doctor. He is just as much an expert on this topic as an average physics teacher is an expert on Quantum Physics without having published scientific articles on that topic.
2) He is involved in multiple vegetarian propaganda organisations:
Speaking at NY Vegetarian Expo
Advisor for Mid-Hudson Vegetarian Society
Member of Physicians Committee for Responsible Medicine (PCRM), which has strong connections with PETA: PCRM and PETA
Speaking at Healthy Lifestyle Expo 2007 with many comments about animals even though he is just a doctor which deals with human.

The “background check” section was rewritten to reflect feedback from comments, thank you.

Install HP LaserJet M1132 MFP printer drivers at Ubuntu 11.10 Oneiric Ocelot Linux hplib hp-setup hp-plugin

UPDATE: For Ubuntu 12.04 it has become much easier to install the HP LaserJet M1132 MFP – use this guide instead if you have Ubuntu 12.04: LINK.

Start your terminal by pressing: CTRL+ALT+T

1. Setup 64 bit libraries for current user:

Make this permanent:
gedit ~/.bashrc

Add these two lines to the end of the file and save it:

Setup t4 bit libraries for root user:
gksudo gedit /etc/

Add the following line to the file and save it:

Now run this command to load the root libraries:
sudo ldconfig


Then follow this guide:

if a plugin is missing, then run (requires that your internet connection is working and that the hplib mirror is online):
sudo hp-plugin -g

You probably have to exit the installer to restart at some point, then run “hp-setup” from the terminal when the computer has restarted.

DONE – gotta love Ubuntu – feel free to comment 🙂

Unity Dash Privacy at Ubuntu 11.10 Oneiric Ocelot

UPDATE: For Ubuntu 12.04 it has become much easier to hide a folder and in general keep things private – just go to “System Settings” and find the “Privacy” button at the “Personal” tab. If you have Ubuntu 12.04 or newer, then I will strongly recommend you to use the built-in Privacy system. However, if you are stuck with Ubuntu less than 12.04, then you can read the following guide:

The Activity Log Manager can exclude certain folders/files from showing up in the Unity Dash on Ubuntu 11.10 Oneiric Ocelot

1. Download latest Activity Log Manager from this site (look for the “Downloads” section to the right of the page):

Here is a direct link for the lazy geeks (but that link will be outdated when a new version of Activity-Log-Manager is released):

2. Unzip the activity-log-manager-0.8.0.tar.gz to somewhere convenient – e.g. your homefolder:

3. Now open a new terminal window by pressing CTRL+ALT+T and navigate to the unzipped folder:
cd /home/YOUR_USERNAME/activityLogJournal

4. Now make activity-log-manager executable:
chmod +x activity-log-manager

5. Run activity-log-manager using the following command:

(If there is some .py error now, then please write a comment to my post including the full error message and then I will try to solve it – It is probably just a missing dependency but make sure that you are using Ubuntu 11.10.)

You should see the following window:
Activity Log Manager used to exclude certain folders/files from Unity Dash on Ubuntu 11.10 Oneiric Ocelot - e.g. your porn folder :)

6. Click the “Files” tab.

8. Click where your username (YOUR_USERNAME) is located (look at where the cursor is located on the previous screenshot).

9. Click “other” and find the folder you want to exclude from the Unity Dash history.

10. Click “Ok” and Click “Add” and from now on that folder will be excluded from the Unity Dash history.

11. DONE. You can also delete any existing Unity Dash history by navigating to the “History” tab (which can be seen on the screenshot above), select the desired timeframe and click “Ok”.

I covered this topic for ubuntu 11.04 in a previous post (), but as that does not work anymore in Ubuntu 11.10, so I thought that I should publish a new guide 🙂

You could also setup a new repository for activity-log-manager instead of downloading the source, but that seems overkill if you are only going to setup the blacklisting once like me.

Ubuntu 4 ever!!! 🙂 Please feel free to leave me a comment, so I know that my effort is not wasted 🙂

Ubuntu 11.04 Unity Dash Privacy

UPDATE: For Ubuntu 12.04 it has become much easier to hide a folder and in general keep things private – just go to “System Settings” and find the “Privacy” button at the “Personal” tab. If you have Ubuntu 12.04 or newer, then I will strongly recommend you to use the built-in Privacy system. However, if you are stuck with Ubuntu less than 12.04, then you can read the following guide:

GUIDE UPDATED FOR UBUNTU 11.10: Unity Dash Privacy at Ubuntu 11.10 Oneiric Ocelot

Ubuntu 11.04 stores history in a component called zeitgeist. This history is also displayed when using the Unity Dashboard, which may show many irrelevant files or private files. Currently, the only way to avoid this is to install the gnome-activity-journal PPA, open it and add entries to its blacklist. Here comes the details:
Install the gnome-activity-journal PPA (the default in the 11.04 repository does NOT work):
sudo add-apt-repository ppa:zeitgeist/ppa
sudo apt-get update && sudo apt-get install zeitgeist gnome-activity-journal

Open gnome-activity-journal PPA -> Open “Preferences” -> go to the “Blacklist” tab and add entries such as:

Later a much better GUI called zeitgeist-global-privacy should makes this much easier.

Mount files in Ubuntu

UPDATE: Save yourself a lot of trouble and get the convenience of a GUI for mounting images – use the FREE program “Furius ISO Mount”, which you can find in Synaptic or the Ubuntu Software Center.. If you really want to mess with low level stuff and scripts, then you can use the following guide…

sudo chmod +x
sudo chmod +r
sudo chmod +r
sudo chmod +x

Now you need to copy them nautilus scripts:

sudo cp ~/.gnome2/nautilus-scripts/
sudo cp ~/.gnome2/nautilus-scripts/

How to use
Rightclick on the image file (e.g. .iso) -> script -> mount/unmount
use the command wine path/to/file.exe to execute files on cd’s
Use IAT to convert weird formats to .iso (sudo apt-get install iat)

sudo chmod +x
sudo chmod +r
sudo chmod +r
sudo chmod +x

# nautilus-mount-iso

gksudo -k /bin/echo "got r00t?"
BASENAME=`basename "${1%.*}"`
sudo mkdir /media/"$BASENAME"

if sudo mount -o loop -t iso9660 "$*" /media/"$BASENAME"
if zenity --question --title "ISO Mounter" --text "$BASENAME Successfully Mounted.

Open Volume?"
nautilus /media/"$BASENAME" --no-desktop
exit 0
sudo rmdir /media/"$BASENAME"
zenity --error --title "ISO Mounter" --text "Cannot mount $BASENAME!"
exit 1

gksudo -k /bin/echo "got r00t?"
BASENAME=`basename "${1%.*}"`
sudo umount /media/"$BASENAME" && zenity --info --text "Successfully unmounted /media/$BASENAME/" && sudo rmdir "/media/$BASENAME/"

Best way to rip music from in Ubuntu

Download videos:
Use Video DownloadHelper extention for Firefox to download videos as .flv or .mp4. (however its conversion functionality is buggy)

Rip video to mp3:
sudo apt-get install ubuntu-restricted-extras
sudo apt-get install ffmpeg
sudo apt-get install winff

Now find winff in Applications -> Sound and Video and use the GUI to rip the videos you have downloaded.

install and setup LAMP on Ubuntu for development

LAMP stack: Linux, Apache, MySQL, PHPMyAdmin
LAMP: Linux Operating System, Apache Webserver, PHP programming language, MySQL database, PHPMyAdmin database web interface

First install Apache2, PHP5, Mysql, Phpmyadmin in that order.

Then lets setup ~/public_html as webroot rather than /var/www/ (because it requires root privileges to modify there which is a pain!):

1. Copy the existing website configuration (virtual directory):
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

2. Modify the following of mysite:
gksudo gedit /etc/apache2/sites-available/mysite
/var/www -> /home/USERNAME/public_html

3. enable mysite and disable default
sudo a2ensite
sudo a2dissite default
sudo /etc/init.d/apache2 reload

/home/USERNAME/public_html can now be accessed as webroot in webbrowser as http://localhost

Setup PHP at this file: /etc/php5/apache2/php.ini
short_open_tag = Off (only use <php ?>? rather than non-standard <? ?> (inverted <)
error_reporting = E_ALL | E_STRICT (see all errors including the E_STRICT ones)
display_errors = On (obvious…)
display_startup_errors = On
html_errors = On

Remember to run this to update the apache configuration:
sudo /etc/init.d/apache2 restart

user = root
Remember to use innoDB as storage engine for mySQL databases as it enables transactions and much more.

access phpmyadmin at localhost/phpmyadmin (use “root” as user)

External guide with lots of more stuff including security: