Page 1 of 2

Viewing mysql db on IE via php

Posted: Mon Mar 28, 2005 7:10 pm
by cdemoneya
Hello Guys,
I'm a newbie to php+sql and I'm having a problem that's really bugging me.
I have installed PHP and Mysql on a server, and created mysql databases and tables which I have been populating with records okay. I have also run small php scripts which have executed okay and the phpinfo(); generates the php welcome page, so I know both work individually.
Now I'm trying to view my "mysql" db on a web page via php, but the number of times I've come up against a blank page is driving me mad.
The code below is what I'm running on a Win2k Server:(host is localhost, root is the username and password is the "root" password)

Code: Select all

<html>
<head>
<title>
dbtest</title>
</head>
<body><pre>
<?
$dbcnx =mysql_connect("localhost","root","password");
         mysql_select_db("test",$dbcnx);
$result=mysql_query("SELECT * FROM customer",$dbcnx);
while ($row=mysql_fetch_row($result))
{
for ($i=0;$i<mysql_num_fields($result); $i++)
echo $row[$i] . "";
echo "n";
}

mysql_close($dbcnx);
?>
</pre>
<font size="1">thank you</font>
</body>
</html>
As you can see this is simple enough.
even when I run:
<html>
<head>
<title>
dbtest</title>
</head>
<body><pre>
<?
$dbcnx =mysql_connect("localhost","root","password");
         mysql_select_db("test",$dbcnx);
$result=mysql_query("SELECT * FROM customer",$dbcnx);
mysql_close($dbcnx);
?>
</pre>
<font size="1">thank you</font>
</body>
</html>
I still come up with a blank page. Apart from this everything works fine. I'm on a deadline, so this is really desperate.Am I missing anything cause everything's been ok till now.

Thanks in advance.

Chuck

Phenom| Please use

Code: Select all

tags for php-code[/size][/color]

Posted: Mon Mar 28, 2005 9:05 pm
by feyd
is it a real blank page, or just an empty <pre> tag?

If it's a real blank page, then you may have an error in the mysql calls. Check your server's error logs, as well as change most of the mysql calls to include the usual debugging stuff like

Code: Select all

mysql_connect('','','') or die(mysql_error());

mysql_query('some query') or die(mysql_error());

Posted: Tue Mar 29, 2005 10:19 am
by cdemoneya
Thanks.
wish I knew what kind of error it was. It generates the simple php scripts I run for tests, so I k now php works. The phpinfo(); bit shows its up and running and mysql is easy to see that the commands are running okay.
I think my problem comes when I try to link the db to the web via php.

1. Would the" or die" command generate an error message,cause if it would generate some error then I'd know where to start, but the freakin blank page winds me up so much.

2.I've saved the file as both .php and .html, but I suppose that wouldnt matter as long as the .html had the php script embedded inside for e.g

<html>
<head>
<title>tester</title>
</head>
<body>
<?
***************.....blah blah
?>
</body>
</html>

The .php is just <? blah blah blah ?> and is not embedded. But I suppose I should get the same result.
Thought it might be my code, but its simple enough to go over although I'll do that again tonite and check the server error log (good call mate - totally skipped my mind, that one)

Posted: Tue Mar 29, 2005 3:03 pm
by infolock
if you put the OR DIE after the sql, an error will come up only if the SQL statement you initiate fails (either trying to connect to the server, db, or query).

if you have a problem in your code, the only way to see where that error is is to either turn on error reporting or write the code to tell it to report a php error.

re

Posted: Tue Mar 29, 2005 8:00 pm
by harrisonad
i also encountered that problem with my new win2k server.
and i found out that by default, php scripts are disabled.
you have to set up your server manually to run scripts.
go to help menu on 'inetmgr' for more info rearding this...

Posted: Wed Mar 30, 2005 12:25 am
by cdemoneya
Thanks guys.
I will try your tips out today and let you know how it pans out.

Harrisonad: will your suggestion (to enable php scripts) still be the case,even if I'm able to run pure php scripts? My problem seems to be with "mysql" connection scripts only. php on its own works fine.

infolock: Turning on error reporting, is this from a windows perspective - i.e. enabling this in inetmgr or php.ini file?

Posted: Wed Mar 30, 2005 12:30 am
by feyd
out of curiosity, what php version are you running?

Posted: Wed Mar 30, 2005 12:34 am
by cdemoneya
by the way feyd.
Thanks for the tip on Event Viewer, I always forget to check that all the time, but in this case, running as smooth as a cucumber. Not a single error reported in any of the categories.
Thanks anyway.

Posted: Wed Mar 30, 2005 12:43 am
by cdemoneya
4.3.10! :cry:

Posted: Wed Mar 30, 2005 12:46 am
by feyd
I wasn't talking about Event Viewer. I was talking about the web server log files.

Posted: Wed Mar 30, 2005 1:16 am
by cdemoneya
sorry!
mine is a networking background,so terminology is easily confused.
not that the log files make a whole lot of sense to me (greek).
these are some of the entries from the night I was battling with it:

Code: Select all

#Software: Microsoft Internet Information Services 5.0
#Version: 1.0
#Date: 2005-03-28 01:08:09
#Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status cs(User-Agent) 
2005-03-28 01:08:09 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 01:36:20 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 01:40:46 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 01:42:22 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 02:11:10 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 02:11:12 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 02:16:05 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 02:45:12 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 03:08:08 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 03:08:11 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 03:38:54 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 03:43:10 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.html - 404 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 03:43:16 127.0.0.1 - 127.0.0.1 80 GET /php+files/dbtest.php - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 10:56:26 127.0.0.1 - 127.0.0.1 80 GET /php+files/welcome1.html - 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 10:57:50 127.0.0.1 - 127.0.0.1 80 GET /phpFiles/phpMyAdmin/ - 302 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 10:57:50 127.0.0.1 - 127.0.0.1 80 GET /phpFiles/phpMyAdmin/ - 403 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 10:58:29 127.0.0.1 - 127.0.0.1 80 GET /phpFiles/phpMyAdmin/ - 302 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 10:58:29 127.0.0.1 - 127.0.0.1 80 GET /phpFiles/phpMyAdmin/ - 403 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:19:54 127.0.0.1 CNENET\Administrator 127.0.0.1 80 GET /iishelp/iis/misc/navpad.gif - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:19:54 127.0.0.1 - 127.0.0.1 80 GET /iishelp/iis/misc/MS_logo.gif - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:19:54 127.0.0.1 CNENET\Administrator 127.0.0.1 80 GET /iishelp/iis/htm/core/iis_banr.gif - 304 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:20:14 127.0.0.1 - 127.0.0.1 80 GET /phpmyadmin - 404 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:35:52 127.0.0.1 - 127.0.0.1 80 GET /phpmyadmin - 404 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:35:54 127.0.0.1 - 127.0.0.1 80 GET /phpmyadmin - 404 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)
2005-03-28 23:36:00 127.0.0.1 - 127.0.0.1 80 GET /iisstart.asp - 302

feyd | added

Code: Select all

tags to make it easier to read[/color]

Posted: Wed Mar 30, 2005 1:34 am
by anjanesh
Why dont you check which one is failing if you are sure its the db problem:

Code: Select all

<?php
$dbcnx = mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("test",$dbcnx) or die(mysql_error());
$result = mysql_query("SELECT * FROM customer",$dbcnx) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
?>

Posted: Thu Mar 31, 2005 12:50 am
by cdemoneya
okay.
Well, at least I'm starting to get some error messages when the DB connections are wrong. Attempt to log on with wrong password or username, generates an "mysql" error.
But still cant display the database as line 6 below doesnt give me anything (error or display).ANY TIPS ON DISPLAYING THIS BIT? :(

6.$row = mysql_fetch_row($result) or die(mysql_error());

Think it worked because, I moved the file code into the wwwroot of the win2k server. I however went to the php.ini and changed the user_dir and pointed it to the a subfolder within wwwroot(where I originally ran the php file) no joy.
Does that mean it definitely has to run from wwwroot folder?
Thanks for your all your help so far.

Posted: Thu Mar 31, 2005 1:22 am
by anjanesh

Code: Select all

<?php
$dbcnx = mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("test",$dbcnx) or die(mysql_error());
$result = mysql_query("SELECT * FROM customer",$dbcnx) or die(mysql_error());
if (mysql_num_rows($result)==0) die("No rows");
$row = mysql_fetch_row($result) or die(mysql_error());
?>

Posted: Thu Mar 31, 2005 2:24 am
by RobertGonzalez
Maybe you can try this:

Code: Select all

if ( $dbconn = mysql_connect("dbserver", "dbuser", "dbpassword") )
{
    echo "I am connected to the DB server!<br />";
}
else
{
    die("Could not connect to the DB server: " . mysql_error());
}

if ( $dbname = mysql_select_db("dbname", $dbconn) )
{
    echo "Now I am connected to the database!<br />";
}
else
{
    die("No Connection to the database: " . mysql_error());
}

$sql = "SELECT * FROM customer";

if ( $result = mysql_query($sql, $dbconn) )
{
    echo "Cool, the query ran OK.<br />";
}
else
{
    die("Sorry, but there was a problem: " . mysql_error());
}

while ( $row = mysql_fetch_array($result) )
{
    echo $row["field_name"] . "<br />";
}
Of course you will have to change all the generic references (such as dbserver, dbuser, field_name, etc) to match your settings. I know it seems like a lot of code, but it might help id any bottlenecks that are logjamming your script.