Page 1 of 1

connecting to remote server database, displays blank page

Posted: Fri Jan 14, 2011 12:06 pm
by dmh188
Hey guys,

I could really use some help understanding what i am doing wrong here and i will try to explain everything the best i can. I am currently running apache on my local computer for work. I am trying to generate a a webpage to run on my computer that will call some sql statements. The database is located on server04. I can use i can use microsoft sql server 2005 express studio just fine to query the data base. I am completely new to php. But i have the apache installed and configured for php and also am putting php page to the htdocs file. Here is the current script i am using (and of course i am changing server, un, dba etc to what it should be:

<?php
$con = mysql_connect("server","un","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

$result = mysql_query("select count(*) from customerordermaster with (nolock)
where shipdate >=
(cast(datepart (mm, getdate()) as nvarchar) +'/'+
cast (datepart( dd, getdate()) as nvarchar) +'/'+
cast(datepart(yyyy, getdate()) as nvarchar))
");

while($row = mysql_fetch_array($result));

?>


Everytime i save this and open it up in the browser by going to the address bar and type localhost/sql.php . But only a blank page displays. Does not even show the text from the document. I have tried variations in the code and even put a kill function in there to release the connection. and i have put it in the middle of <body> on an html doc. any help would be very much appreciated!

Re: connecting to remote server database, displays blank pag

Posted: Sat Jan 22, 2011 8:46 am
by jamies111
Do other pages work on the web server, or is this the first one?

I use a test page with phpinfo(); to make sure the server is working. You may need to adjust the error display settings in php.ini also, as there may be an error that is preventing the script from completing, such as an SQL error.

You could try the following to get the count:

Update the begginning of the SQL query to:
[text]"select count(*) as total from customerordermaster ... "[/text]

At the end of your script, you could also add (replace the existing while statement):
[text]$row = mysql_fetch_assoc($result);
echo $row['total'];[/text]