Problems trying to get MySQL to work from PHP script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm having trouble getting a new PHP/MySQl installation to work.

Windows XP Pro, IIS 5.1, PHP 5.1.1, MySQL 5.0.16, ISAPI

This is a new computer. The whole setup is for development use only -
no access from beyond my own network.

PHP seems to be working OK. I can open a test.php page ok - It
executes down to the statement where I try to connect to the MySQL
database. At that point, nothing further happens. The page is served
out. No errors are generated.

MySQL also seems to be working. I've installed MySQL Administrator
and, from what I can see, everything looks OK. I have a database - it
has tables in it - the tables have data in them - I can execute
queries against them. This database is a copy of one I developed on
another machine

FWIW, the MySQL extension is activated in the PHP.INI file thus:

Here's the beginning of the script in the test.php page:
Here we go!


echo("<br>Inside the php script!");

$conn=@mysql_connect( "localhost", "root", "admin" );
echo("<br>Connected to the database!");

$rs = @mysql_select_db( "crowdwisdom", $conn );

When this runs, the displayed page consists of:
Here we go!
Inside the php script!


Re: Problems trying to get MySQL to work from PHP script

Martin wrote:

Quoted text here. Click to load it

Your problem is that you don't know php. If mysql_connect() fails, your
program won't print any errors and it won't stop there. The @-characters
in front of a function disables printing of any internal error messages
and since you don't even thech the result of $conn, you won't get any
information if the function fails or doesn't fail.


$conn=mysql_connect( "localhost", "root", "admin" );
if( !$conn )
   die( "<br>Database connection failed!" );

echo("<br>Connected to the database!");

Re: Problems trying to get MySQL to work from PHP script

On Mon, 05 Dec 2005 20:48:28 +0000, Aggro wrote:
Quoted text here. Click to load it

Inflamatory considering that you seem to have misunderstood his point...

Quoted text here. Click to load it

I think you're missing the OPs point.  The code (better formatted as you
typed it above) should try to connect to the database (without printing
errors or stopping).  Then it should print a line of text (regardless of
connection or not).

The OP is saying it never gets that far!  It only prints the first line,
which means the script is stopping on the mysql_connect line, not just
failing to connect.

To be honest, I'd say that for some reason it's not recognising the MySQL
extension and if you remove the @ symbol you'll get a fatal error saying:

"undefined function mysql_connect"

The script is therefore stopping at that point but your @ is supressing
the printing of the message.

But that's just a best guess, I've never had PHP not recognise the MySQL
extension, but then again I've never installed it on Windows...



Andy Jeffries                 | gPHPEdit Lead Developer | PHP editor for Gnome 2 | Personal site and photos

Re: Problems trying to get MySQL to work from PHP script

Andy Jeffries wrote:

Quoted text here. Click to load it

I don't think I missed the point, but I admit that I didn't read the
whole message very carefully. The reason for that is that I wouldn't
bother solving the real problem before I had fixed the first problem.
And the first problem was that no error messages were printed out while
there surely were errors.

But thank you for making this clear.

Site Timeline