Archive

Archive for February, 2009

Using Ternary PHP Conditionals (short hand)

February 26th, 2009

Standard php conditional:

  1. if (date("G") < 12) {
  2. echo 'Good morning';
  3. } else {
  4. echo 'Good afternoon';
  5. }

Shorthand…

  1. $greeting = (date("G") < 12) ? 'Good morning' : 'Good afternoon';
  2. echo $greeting;

(http://www.addedbytes.com/php/ternary-conditionals/)

PHP

Accessing MySQL Remotely

February 25th, 2009

Say for example, you have a web page you want to access some data on but the database is located on a different server. To do this you will need to add another user to the mysql.users table and specify the remote location where you are accesing from.

$ mysql -u root -p

mysql>  GRANT ALL PRIVILEGES ON database_name.* TO myUser@host_name IDENTIFIED BY 'pass' WITH GRANT OPTION;

*user ‘%’ for hostname if wanting to accept connections from all hosts.

mysql> Flush priviledges

Next, edit your /etc/mysql/my.cnf file:

Comment the bind-address

#bind-address: 127.0.0.1  //if enabled with disallow connections from a remote host.

Restart mysql:

# /etc/init.d/mysql restart

Uncategorized, mysql

Get all data in protected HTTP folder

February 4th, 2009

Uncategorized

Python - SyntaxError: Non-ASCII character ‘\xe2′

February 4th, 2009

Problem: When executing a python script you get the following error:

SyntaxError: Non-ASCII character ‘\xe2′ in file /usr/share/onboard/utils.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

The Fix:

Add

# -*- coding: utf-8 -*-

to the top of your document

Uncategorized