SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed on nearly complete site

    I have a non-profit Christian school site that asked me to create a custom CMS so they could update the main parts of their site in-house. I'm a front-end developer, but wanted to learn more PHP, so I created the CMS and the site to read the database as needed. Through assistance from this forum, I was able to get it working correctly on my computer's MAMP server.

    Unfortunately, when I moved it to the live server, more errors came up. Two scripts are coming up with undefined variables, but despite multiple checks, I can't see the error. The variables are defined and work on MAMP, just not the live server. I have asked for assistance here, but it seems to no avail.

    As school is starting in a few weeks for them, this project needs to be fully functioning. After completely volunteering my time and spending four months working on it through other work, I'm tired of it. I need either assistance in finding the problem or another developer that's willing to step in and work on it.

    Ideally, it needs to be done by August 9, but earlier is better. The offending scripts are listed below, but anyone willing to offer help is appreciated. The DbFactory was totally new to me, which wouldn't take much, but since I had everything working, I don't believe it's the problem.

    DbFactory.php
    PHP Code:
    <?php 
    class DbFactory{
      private static 
    $factory;
      public static function 
    getFactory(){
          if (!
    self::$factory){
            
    self::$factory = new DbFactory();
            return 
    self::$factory;
          } else {
            throw new 
    exception('DbFactory could not return database instance.');
          }
      }
      private 
    $db;
      public function 
    getConnection(){
          if (!
    $db)
               
    $db = new PDO("mysql:host=216.51.232.202;dbname=name""user""pass");
          return 
    $db;
      }
    }
    ?>

    getschedule.php
    PHP Code:
    <?php
    $o_Db 
    DbFactory::getFactory()->getConnection();

    function 
    GetSchedule(PDO $o_Db$table_name$fields){
      if(!
    $o_Db || !$table_name || !fields){
        throw new 
    exception('GetData(PDO $o_Db, string $table_name, array or string $fields. You did not pass one of the variables');
      }
      if(
    is_array($fields)){
        
    $fields_count count($fields);
        
    $i 1;
        
    $sql_fields null;
        foreach(
    $fields as $value){
          if(
    $i $fields_count){
            
    $sql_fields .= "$value, ";
          } else {
            
    $sql_fields .= "$value";
          }
          
    $i++;
        }
      } else {
        
    $sql_fields htmlentities($fields);
      }
      
    $table_name htmlentities($table_name);

      
    $sql "SELECT datetext FROM schedule";
      
    $stmt $o_Db->prepare($sql);
      
    $stmt->execute();
      return 
    $stmt->fetchAll(PDO::FETCH_ASSOC); 
      }
    ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    more errors came up.
    This sounds as if you mean there were already some errors, were there? and if so what were they?

    Two scripts are coming up with undefined variables
    What are they then?

    What else is going wrong, you posted some db connection stuff, is that the only thing that is wrong?

    Did you compare the output of phpinfo() on both servers to see what differences there are? If not, do that now.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    This sounds as if you mean there were already some errors, were there? and if so what were they?
    Just bad wording on my part. The errors I had when doing initial development were all resolved. No errors existed on my local MAMP version of the site when I uploaded it to the active server.

    Quote Originally Posted by Cups View Post
    What else is going wrong, you posted some db connection stuff, is that the only thing that is wrong?
    The two errors that are being reported are:
    1) Undefined variable: db in E:\Websites\1414\sullychristian.org\assets\includes\DbFactory.php on line 14

    2) Use of undefined constant fields - assumed 'fields' in E:\Websites\1414\sullychristian.org\assets\includes\getschedule.php on line 5

    Those are the two files posted above. I haven't done the comparison or knew you could, so doing it now. I did use PHPMyAdmin and MySQL in the host's server to initially put some data in the database and it's coming up on the site as it should be.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    <?php  
    class DbFactory
      private static 
    $factory
      public static function 
    getFactory(){ 
          if (!
    self::$factory){ 
            
    self::$factory = new DbFactory(); 
            return 
    self::$factory
          } else { 
            throw new 
    exception('DbFactory could not return database instance.'); 
          } 
      } 
      private 
    $db
      public function 
    getConnection(){ // note $this-> was added
          
    if (!$this->db
               
    $this->db = new PDO("mysql:host=216.51.232.202;dbname=name""user""pass"); 
          return 
    $this->db
      } 

    ?>
    PHP Code:
       <?php 
    $o_Db 
    DbFactory::getFactory()->getConnection(); 

    function 
    GetSchedule(PDO $o_Db$table_name$fields){ 
      if(!
    $o_Db || !$table_name || !$fields){ ... // note the $ before fields added
    Those are both critical errors that should have not worked on your local box.
    The only code I hate more than my own is everyone else's.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks oddz, that fixed the error on the DbFactory, now on to getschedule.

    I added "echo phpinfo()" to a page and got a lot of information. The only main thing I see is that the active server is on version 5.2.14 and MAMP is 5.3.6. With both being version 5, I wouldn't think a large discrepancy would occur.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vmtech View Post
    Thanks oddz, that fixed the error on the DbFactory, now on to getschedule.

    I added "echo phpinfo()" to a page and got a lot of information. The only main thing I see is that the active server is on version 5.2.14 and MAMP is 5.3.6. With both being version 5, I wouldn't think a large discrepancy would occur.
    Not sure if you saw it, but oddz fixed your getschedule issue too, your first if statement is missing the $ in front of "fields".

    Are there any additional issues you need help with?

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope I missed it oddz, sorry, but that also fixed it. It proves that more eyes are better, I've been looking at that line for weeks and didn't see it.

    I think that's all, thanks everyone!

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but I ran into another error when logging in to the CMS.

    Fatal error: Call to undefined function mysqli_connect() in E:\Websites\1414\sullychristian.org\assets\includes\connect.php on line 5

    connect.php
    PHP Code:
    <?php
    // Removed comment
    // Removed comment

    $link mysqli_connect('216.51.232.202''user''pass');
    if (!
    $link)
    {
        
    $error 'Unable to connect to the database server.';
        include 
    'error.php';
        exit();
    }

    if (!
    mysqli_set_charset($link'utf8'))
    {
        
    $output 'Unable to set database connection encoding.';
        include 
    'error.php';
        exit();
    }

    if (!
    mysqli_select_db($link'database'))
    {
        
    $error 'Unable to locate the Sully database.';
        include 
    'error.php';
        exit();
    }
    ?>
    The comments are just reminders for the different database connections.

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Check phpinfo() but it could be that the version of php on the server isn't compiled against mysqli or isn't setup to load it in the php.ini

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, PHP novice, what line do I look at? It's up at http://www.sullychristian.org/admin/

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    If mysqli is active, you should see something like this:
    Code:
    mysqli
    
    MysqlI Support	enabled
    Client API library version	5.1.63
    Active Persistent Links	0
    Inactive Persistent Links	0
    Active Links	0
    Client API header version	5.1.49
    MYSQLI_SOCKET	/var/run/mysqld/mysqld.sock
    
    Directive	Local Value	Master Value
    mysqli.allow_local_infile	On	On
    mysqli.allow_persistent	On	On
    mysqli.default_host	no value	no value
    mysqli.default_port	3306	3306
    mysqli.default_pw	no value	no value
    mysqli.default_socket	no value	no value
    mysqli.default_user	no value	no value
    mysqli.max_links	Unlimited	Unlimited
    mysqli.max_persistent	Unlimited	Unlimited
    mysqli.reconnect	Off	Off
    When I went to your site, I did not see anything like the above. So that tells me mysqli is not setup on your remote server.

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    IA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great, back to the drawing board. Thanks again. Any suggestions where to go for the connection now? Is it possible to take the dbfactory's connection and use it for this? Since the site displays what's in the database, I'm assuming it's connecting via DbFactory.

  13. #13
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Change mysqli and any other related mysqli functions to mysql (note, some mysqli functions are named differently, so you may need to search php.net to find the correct mysql function)

  14. #14
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So, this site depends on both PDO and Mysqli? - personally I'd forget converting Mysqli to mysql, if PDO is working as expected I'd stick to PDO for all db transactions.

    EDIT

    Is there some legacy code you imported that used Mysqli? I guess its a moot point which is easier to rewrite, Mysqli to mysql or Mysqli to PDO - maybe it will come down to how many lines of code there are.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •