tags:

views:

167

answers:

2

Hello! I have a problem with Apache, which restarting, when I want to open PHP code in browser. Code :

require_once 'DB.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);

$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'marylover';
$db_name = 'test';
$dsn = "mysql://$db_user:$db_pass@unix+$db_host/$db_name";
$db = DB::connect($dsn);

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.

A: 

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

Inspire
Ok..1) No *PEAR::setErrorHandling(PEAR_ERROR_DIE);* --->same problem;2) With this sample code --->the same problem (Apache HTTP Server error in browser);3) No *--with-mysql-sock* string in phpinfo();
Evgeni
Do you get an Internal Server Error (HTTP 500) response from Apache when running the sample code I posted? It sounds like you have a problem with your PHP build then or mysql extension configuration as even if the connection fails in that sample code you should only receive PHP E_WARNING notices.
Inspire
Granted privileges to 'deadlyhunta';Now< i use this code, correct?<?phperror_reporting(E_ALL);ini_set('display_errors', 1);$conn = mysql_connect('localhost', 'deadlyhunta', 'marylover');mysql_select_db('test', $conn);?>when I run it from browser I recieve Windows notice with Sent Error Report or Don't Send (Apache HTTP Server has encountered a problem and needs to be closed). Clicking *don't send* and browser continues "thinking" then that window again, and so on. Is there need to be values in MySQL part of phpinfo.php?Like mysql.default_host, mysql.default_password and others?
Evgeni
Maaan. I'm stupid russian moron. During mass-reinstall PHP/Apache/MySQL I changed libmysql.dll in windows/system32 dir on wrong one. No changed back and everything works fine! Thank you for INSPIRation! Sorry such a brainless *noun* took your time. Thanks again!
Evgeni
I would recommend you install XAMPP (http://www.apachefriends.org/en/xampp.html) to use for local testing to replace your current setup as there is a serious issue somewhere in your current Apache and PHP setup which is causing it to crash. Incorrect default mysql options in php.ini should not cause a full server crash like that.
Inspire
A: 

I am stupid! With hands out of ass. Thanks everyone for their help!

Evgeni