Page 1 of 2

Not getting anything from the DB

Posted: Fri Sep 30, 2011 10:57 am
by Taruka
First of all, I am a N00B when it comes to PHP. Have been working for a long time with ASP and are determined to switch now. Some say, I have seen the light. :lol:

Anyway, started with a Windows 7 64Bit machine running IIS, installed PHP and off I whent. Made some pages echoing text, comparing, some forms, transfer a value to a second page. Easy stuff...

Install MySQL5.5, and this is where the problems started... Getting information from the database :oops:

Using the MySQL Workbench I can open the DB, make some collumns and add the data. So now I have a DB called "test", it holds a table with the name "employees" and it has a value to retrieve with the name "employee", or "ID". Doesn't matter.

Image

Took an example from the W3SCHOOLS website and changed it to match my own setup.

Code: Select all

<html>
<body>

<?php
echo "hier begint de connectie";
 $con = mysql_connect("localhost","root","*******");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
 
mysql_select_db("test", $con);
 
$result = mysql_query("SELECT * FROM employees");
 
while($row = mysql_fetch_array($result))
   {
   echo $row['Employee'];
   echo "<br />";
   }
 
mysql_close($con);
?>

</body>
</html>
Now, with this nothing is produced on the screen. No error message, not output from the DB either.

- When I change the server name in the connection, the password or the username nothing happens either...

And I am staring and staring, but can't seem to put the finger on the problem

Any suggestions???

Re: Not getting anything from the DB

Posted: Fri Sep 30, 2011 11:07 am
by Celauran
What output does this produce?

Code: Select all

var_dump($result);

Re: Not getting anything from the DB

Posted: Wed Oct 05, 2011 8:42 am
by Taruka
Hi

I have added the statement just before the closing. But nothing happens on the screen... :?

Code: Select all

<html>
 <body>
 
<?php
 echo "hier begint de connectie";
  $con = mysql_connect("localhost","root","*******");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  
 mysql_select_db("test", $con);
  
 $result = mysql_query("SELECT * FROM employees");
  
 while($row = mysql_fetch_array($result))
    {
    echo $row['Employee'];
    echo "<br />";
    }
 var_dump($result);  
 mysql_close($con);
 ?>
 
</body>
 </html>

Re: Not getting anything from the DB

Posted: Wed Oct 05, 2011 8:44 am
by Celauran
Put it right after $result = mysql_query("SELECT * FROM employees");

Re: Not getting anything from the DB

Posted: Wed Oct 05, 2011 10:31 am
by Taruka

Code: Select all

<html>
 <body>

<?php
echo "This is where the connection starts";

$con = mysql_connect("localhost:3306","root","********");
 
mysql_select_db("php-test", $con);
 
$result = mysql_query("SELECT * FROM New_Table");
var_dump($result); 
 
//while($row = mysql_fetch_array($result))
//   {
//   echo $row['FirstName'];
//   echo "<br />";
//   }
mysql_close($con);
?>
</body>
 </html>
Nope, nothing. I am realy wondering about the whole connection thing. When I change the password to something complete else it does not even complain. Change the DB to a non existing name and it does not complain...

Weird.

Re: Not getting anything from the DB

Posted: Wed Oct 05, 2011 10:34 am
by Celauran
Doesn't make sense that var_dump isn't producing any output. Have styles been applied to the page, leading to possibly black text on a black background? Have you viewed the source?

Re: Not getting anything from the DB

Posted: Wed Oct 05, 2011 3:02 pm
by califdon
This sounds like your IIS web server isn't processing the PHP code. As you may know, IIS doesn't support PHP natively, it has to be configured to call a .dll, I believe. Look at the source code, in your browser; are the <html> and <body> tags coming through? If they are, your problem could be that IIS is not configured for PHP. Also, be aware that PHP syntax errors will often produce a blank screen like that, although I don't see any such errors in the code that you posted. For details on installing PHP with IIS, see http://www.php.net/manual/en/install.windows.iis.php.

[Edit:] I assume that your PHP script is in a file with a filename suffix of .php; that's critically important to cause the web server to preprocess the file using the PHP parser.

Re: Not getting anything from the DB

Posted: Thu Oct 06, 2011 2:09 am
by Taruka
Celauran wrote:Doesn't make sense that var_dump isn't producing any output. Have styles been applied to the page, leading to possibly black text on a black background? Have you viewed the source?
To keep it simple for myself I am only using one page right now. default.php. The code in the page is show in the post above your comment. That is all. I have commented out the code that prints the output to the screen as I am only looking for the result of the var_dump code right now. But removing the comment code does not change the ouput.

Re: Not getting anything from the DB

Posted: Thu Oct 06, 2011 2:13 am
by Taruka
califdon wrote:This sounds like your IIS web server isn't processing the PHP code. As you may know, IIS doesn't support PHP natively, it has to be configured to call a .dll, I believe. Look at the source code, in your browser; are the <html> and <body> tags coming through? If they are, your problem could be that IIS is not configured for PHP. Also, be aware that PHP syntax errors will often produce a blank screen like that, although I don't see any such errors in the code that you posted. For details on installing PHP with IIS, see http://www.php.net/manual/en/install.windows.iis.php.

[Edit:] I assume that your PHP script is in a file with a filename suffix of .php; that's critically important to cause the web server to preprocess the file using the PHP parser.
I mmight be a beginner, but not that much of a beginner. :D

I have installed PHP on IIS and I believe it is working as I have started with the more simple PHP code such as echo something to the screen, create a form and transport a value to the next page and work with it. The code I have been playing with is down here. Once I started with the database connection I remove it from this page to not confuse me (not that I needed to as what I am left is confusing the h... out of me... :crazy: )

Code: Select all

echo "Hello World";

$MyFirstVariable = "And this is the text that goes with the string";
echo $MyFirstVariable;

$d=date("D");
if ($d=="Fri") 
echo "Have a nice weekend!";
else
echo "Sorry, not yet weekend"; 


Thanks for helping out to all of you...

Re: Not getting anything from the DB

Posted: Thu Oct 06, 2011 8:11 pm
by califdon
So you are saying that this last code you showed does produce the expected output? It's only when you try to connect to MySQL that you get the blank screen? I think that I would go back to the first code that you posted, and insert a line of HTML before the <?php. It should display. Let us know if it does.

Re: Not getting anything from the DB

Posted: Fri Oct 07, 2011 1:54 am
by Taruka
califdon wrote:So you are saying that this last code you showed does produce the expected output? It's only when you try to connect to MySQL that you get the blank screen? I think that I would go back to the first code that you posted, and insert a line of HTML before the <?php. It should display. Let us know if it does.
The code echo "Hello World" and the code with the $MyFirstVariable is producing output. What tells me that the PHP part is installed properly and working. It is indeed only the information I am retrieving from the database that is not showing. And funny enough, even the connection to the database, with the username and the password, is funky. As I can use any username and any password that does not exist with no error message what so ever.

Re: Not getting anything from the DB

Posted: Fri Oct 07, 2011 12:20 pm
by califdon
I would recommend that you uninstall MySQL and then re-install it.

Re: Not getting anything from the DB

Posted: Fri Oct 07, 2011 1:26 pm
by mikosiko
what is the output of phpinfo() regarding mysql?

Code: Select all

<?php
   phpinfo();
?>
you already did enable the php_mysql and/or php_mysqli extension in php.ini .... and rebooted the IIS... right?... and also you included the PHP path in your PATH variable ?

Re: Not getting anything from the DB

Posted: Mon Oct 10, 2011 6:19 am
by Taruka
mikosiko wrote:what is the output of phpinfo() regarding mysql?

Code: Select all

<?php
   phpinfo();
?>
you already did enable the php_mysql and/or php_mysqli extension in php.ini .... and rebooted the IIS... right?... and also you included the PHP path in your PATH variable ?
Going to double check the INI file right now. Can't remember making those changes.

Re: Not getting anything from the DB

Posted: Mon Oct 10, 2011 6:44 am
by Taruka
mikosiko wrote:what is the output of phpinfo() regarding mysql?

Code: Select all

<?php
   phpinfo();
?>
you already did enable the php_mysql and/or php_mysqli extension in php.ini .... and rebooted the IIS... right?... and also you included the PHP path in your PATH variable ?
Here is a copy paste from the PHP.INI

[text]extension=php_mime_magic.dll
[PHP_MING]
extension=php_ming.dll
[PHP_MSQL]
extension=php_msql.dll
[PHP_MSSQL]
extension=php_mssql.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OCI8]
extension=php_oci8.dll
[PHP_OPENSSL]
extension=php_openssl.dll
[PHP_PDO][/text]

The PHP install directory is listed in the path statement.
PATH=C:\Program Files (x86)\PHP\;C:\Program Files\Common Files\...etc etc