Friday, October 27, 2006

Upgrading to PHP 5 -- fix 3

And, of course, there's the famous "backslash" or "magic_quote" problem. The only way to sensibly develop a large PHP app is to turn magic_quote Off in the php.ini file. That way, you can get reliable behavior from addslashes & stripslashes. When you port to a new php implementation, however, you'll find that, by default, magic_quotes is On. Edit php.ini, turn magic quotes Off, issue a /etc/init.d/apache2 restart, and your text inserts & fetches shouls be fine.

Sunday, October 22, 2006

Upgrading to php5 -- fix 2

I get:

"Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' " ....

I notice that my old command line entrance into mysql isn't working, and I get:

"Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' "

Ah ... mysqld isn't running. So:

mysqld_safe &

... which finds the old config files fine. Errors disappear. Everything's up.

Upgrading to php5

After a major Linux distro upgrade

This message (from php):

Fatal error: Call to undefined function: mysql_connect() ...

Mysql wasn't bundled in. So I typed:

apt-get install php5-mysql

... which fixed the problem

Sunday, October 15, 2006

Odd characters in PHP server output

Switched from php4 to php5.

First problem: strange control characters that the browser renders as black diamonds with a question mark inside. Like this: ��

So I saved the html file.

Looked at it with vim -b.

The confused black diamonds were "a0" in hex.

I typed "a0" into Google.

Others had this problem, with perl. It was a matter of content-type character sets (charset): is0-8859-1 vs. UTF-8 ...

Looked at the HTML output of another server I had (with php4) for phpinfo(). Compared side-by-side with the php5 output. Very useful ... a bunch of sections with settings in tables. It was in a section entitled "HTTP Headers Information", subheading "HTTP Response Headers". The good server had the name/value pair:

Content-Type text/html; charset=iso-8859-1

... the bad, problem server had:

Content-Type text/html; charset=UTF-8

So, I looked at the /etc/php5/apache2/php.ini file.

there's a line that read:

;default_charset = "iso-8859-1"

I tried removing the leading semi-colon (uncommenting). Typed:


And that fixed it. The diamonds disappeared.