Interesting problem..cannot get output using database class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
erupt
Forum Commoner
Posts: 58
Joined: Sat Feb 25, 2006 10:24 am

Interesting problem..cannot get output using database class

Post by erupt »

Here's my problem. I'm trying to create a database class to use as an 'include' file. I should first start off by saying i'm using Zend Development environment as my IDE. I've created the include file and here is the code for that..

Code: Select all

//database_include.php

Class clsData
{

Function dbconn()
  {
      $connection = mysql_connect("myserver", "myusername", "mypassword");
      
      if(!connection)
          {
               echo mysql_error();
          }
          else
          {
               echo "Successful connection";
          }

          $selection = mysql_select_db("mydatabase");
           if(!selection)
           {
               echo ("Database was not selected");
           }
           else
           {
                echo("Database was selected fine");
           }

   }

}


Here is the page I'm using to try and output the results:

Code: Select all

//test.php

<?php include ("mydirectory/database_include.php"); ?>

<?php

$cls = new clsData;

$cls->dbconn();

?>
Here's the strange thing. When I run test.php inside the Zend Studio IDE by using Debug > Run, the results display correctly in the debut output screen inside the Zend IDE. But when I try to run test.php from my browser, either firefox or IE, I get a completely blank screen. Blank white screen, I go an view source and there's absolutely nothing there. It appears to work (theoretically) because I can see the correct output through the debug output window in Zend Studio. As you can see this code is pretty straightforward and is strictly for testing purposes; I want to see if I can work with a database include file. Any ideas? Has anyone seen this strange (or maybe not so strange) error? If I am not being thorough enough please let me know and I will do my best to be more thorough and clearer. Thanks in advance.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Interesting problem..cannot get output using database class

Post by John Cartwright »

Put

Code: Select all

error_reporting(E_ALL); 
at the top of you're script, you'll notice you have some undefined variables that need to be dealt with.
Post Reply