PHP Parse error: syntax error, unexpected $end

The following error may appear in your Apache error log file or displayed on a PHP web page:

Parse Error: syntax error, unexpected $end in ….. scripts.php on line …

If you are running PHP 5 then that means you probably need to enable the PHP configuration file option “short_open_tag”. In your php.ini file enable the option as follows:

short_open_tag = On

How to Query Multiple Databases in PHP

You can perform a SQL query against more than one database with PHP. Here is a sample generic SQL query against two databases:

SELECT image.image_title, greetings.date
FROM db1.image, db2.greetings
WHERE greetings.image_id=image.imageid

And here is some PHP sample code on how you would query two databases in a single SQL statement:

$query="INSERT INTO db1.table1 SELECT * FROM db2.table2 WHERE a=1";
mysql_query($query,$connection);

Error When Compiling PHP in CentOS 64 Bit

Library files in CentOS 64 bit are stored in the directory /usr/lib64. But in normal 32 bit CentOS, library files are stored in /usr/lib so this causes a problem when trying to compile source code that looks for library files in /usr/lib. When using the default configure options for compiling PHP, the directory /usr/lib is searched for library files so if you have any 64 bit applications installed, their associated library files will not be found. For example, trying to compile PHP with the configure option:

--with-mysql=/usr

will result in the error:

/usr/bin/ld: cannot find -lmysqlclient

You can fix this MySQL error and other configure errors relating to library files not being found by adding the following option to the configure line:

--with-libdir=lib64

Code

PHP – How to Display REQUEST, POST, and SESSION Variables

Here is some quick and dirty PHP code to display all request variables available to a page. This is useful while debugging:

foreach($_REQUEST as $var=>$val)
{
   echo "$var=$val";
}

Replace _REQUEST with _POST or _SESSION and you can see those variables too.

Code