开发者

mysql_connect() causes page to not display (WAMP)

I currently have a website running MySQL and PHP in which this is all working. I've tried installing WAMPServer to be able to work on the site on my own computer, but I have been having issues trying to get the site to work correctly.

HTML and PHP files work correctly (by going to http://localhost/index.php, etc.). But some of the pages display "This Webpage is not available" (in Chrome) or "Internet Explorer cannot display this webpage", which leads me to think there is an error is the server, as when the page doesn't exist, it typically dispays "Oops! This link appears to be broken" or IE's standard 404 page.

Each page in my site has an include() call to set up an instance of a class to handle all database transactions. This class opens the connection to the database in its constructor. I have found commenting out the contents of the constructor will allow the page to load, although this understandably causes errors later in the page.

This is the contents of the included file:

class dbAccess  {
    private $db;

    function __construct() {
        $this->db = mysql_connect("localhost","root","") or die ("Connection for database not found.");

        mysql_select_db("dbName", $this->db) or die ("Database not selected");
    }
    ...
}

As a note for what's happening here. I'm attempting to use the database on my site, rather than the local machine. The actual values of dbName, user, and password work when I plug them into my database software (Navicat Lite) and work correctly on the finalized version of the site, so I don't think the issue is with those values themselves, but rather some setting with Apache or Wamp.

This is an excerpt of my Apache error log for one attempt at logging into the site:

[Wed Apr 14 15:32:54 2010] [notice] Parent: child process exited with status 255 -- Restarting.
[Wed Apr 14 15:32:54 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Apr 14 15:32:54 2010] [notice] Server built: Dec 10 2008 00:10:06
[Wed Apr 14 15:32:54 2010] [notice] Parent: Created child process 1756
[Wed Apr 14 15:32:55 2010] [notice] Child 1756: Child process is running
[Wed Apr 14 15:32:55 2010] [notice] Child 1756: Acquired the start mutex.
[Wed Apr 14 15:32:55 2010] [notice] Child 1756: Starting 64 worker threads.
[Wed Apr 14 15:32:55 2010] [notice] Child 1756: Starting thread to listen on port 80.

I've tried searching for solutions online, but haven't been able to find anyt开发者_如何学Ching to help. If you need any further information to help solve this issue, feel free to ask for it.

(One more note, I don't even have Skype on this computer, so I can't see it being an issue, as this conflict seems to be the default response for any Wamp issue.)

[Edit: Removed entry from the error log as it was solved as an unrelated issue] [Edit: Looking through my hosts documentation, I found that all ports besides 80 and 443 (for HTTP and HTTPS) are blocked, meaning they don't allow external connections like what I was trying to do here. I've changed it to the local database, but I'm still receiving the same error. The issue is still open.]


I too encoutered this problem. The solution for me was to move the mysql_connect method out from its class and just call it directly.


Let's by-pass the apache for a moment. In the directory <wamp>/bin/php/php5.3.0 there is a php.exe that implements the cli sapi (the command line version).

Put the file test.php in that directory with

<?php
if ( !extension_loaded('mysql') ) {
    die('the mysql extension is not present');
}

echo 'phpversion=', phpversion(), "\n"; flush();
echo 'client_info=', mysql_get_client_info(), "\n"; flush();

$mysql = mysql_connect('localhost', 'root', '') or die(mysql_error());
echo "seems to be working\n"; flush();

echo 'server_info=', mysql_get_server_info($mysql), "\n"; flush();

as the content. Then open a command shell, "go" to the directory

c:
cd c:\wamp\bin\php\php5.3.0

and run

php.exe -f test.php

It should print something like

phpversion=5.3.2
client_info=mysqlnd 5.0.7-dev - 091210 - $Revision: 294543 $
seems to be working
server_info=5.1.37

(though the versions will be different in your case)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜