When you say:
It's crashing on the last line -> cannot connect to MySQL, I think. I want to use PEAR and Apache, but it seems they don't like each other. Help me, please! Thanks.
I'm assuming you mean at the PHP level (ie your script quits, there is no "crash" at the webserver level)?
The build of PHP being used with Apache is most likely going to be different to what you're using with your IDE (phpDesigner). The mysql extension in the PHP build being used with Apache could be trying to connect to MySQL differently (for example via a socket file that does not exist).
Unless I've misunderstood, it would seem the script is exiting because it can't connect to the database server.
This line looks like it would cause this to happen:
PEAR::setErrorHandling(PEAR_ERROR_DIE);
You should try running some sample code to see if the error lies with establishing a connection to MySQL:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$conn = mysql_connect('localhost', 'root', 'marylover');
mysql_select_db('test', $conn);
Also check your configure command via phpinfo() and see if either of your PHP build's has been compiled with the --with-mysql-sock option