Hey guys,

I'm new to php / sql and all the fun that comes with it 🙂

But I bought a php book awhile back about how to make php based games, its very informative but lacking in some areas. It came with a cd and example files.

But I'm having trouble getting the database up and running, dont know where to get db.php or what to put in it 🙂

I created my own db.php and put code I found online in it. (Guess work)

<?php
//config file
ob_start();
//database info
$g_DBHost = 'localhost';
$g_DBUsername = 'root';
$g_DBPassword = '';
$g_DBName = 'example';
//end db info
//connect to db
mysql_connect($g_DBHost, $g_DBUsername, $g_DBPassword)
   or die('Could not connect: ' . mysql_error());
mysql_select_db($g_DBName) or die('Could not select database');
//end connect
?>

Doing this stopped some of the errors I was getting, but now when i click login the page just refreshes.

Heres one error i get when trying to register a user.

fatal error: Undefined class name 'db' in c:\program\files\easyphp1-8\www\CLockTableCmd.php on line 11

Any help with this would be great, thanks 🙂

p.s : Go easy on me :queasy:

    You'll have to supply us a bit of CLockTableCmd.php so we can see what you're trying to do on line 11.

      Here she is,

      <?php
      require_once( "DB.php" );
      require_once( "CCommand.php" );
      require_once( "CUnlockTableCmd.php" );
      require_once( "settings.php" );
      class CLockTableCmd extends CCommand
      {
      	function Execute( $sTableName )
      	{
      		// connect to the db
      		$db = DB::connect( $GLOBALS['g_PearDBDSN'] );
      	if (DB::isError( $db ))
      		{
      			// let everyone know that there has been a problem
      			$this->OnError("Failed to connect to the database using " . $GLOBALS['g_PearDBDSN'] . $db->getMessage());
      			// return failure
      			return CMD_ERROR;
      		}
      		// try to lock
      		$result = $db->Query( "LOCK TABLES $sTableName WRITE" );
      		if (DB::isError( $result ))
      		{
      			// let everone know there is a problem
      			$this->OnError("Failed to lock $sTableName");
      			// return failure
      			return CMD_ERROR;
      		} else {			
      			// it is only if we reach this far that we 
      			// need to worry about rolling back the command
      			$this->m_bNeedRollBack = true;
      		}
      			// this command is successfully completed	
      		return CMD_FINISHED;
      	}
      	function OnRollBack()
      	{
      		// if we don't need to roll back, don't
      		if ( $this->m_bNeedRollBack == false )
      		{
      			return;	
      		}
      				// create an instance of the unlock table command with no parent
      		$unlock = new CUnlockTableCmd( $null );
      		// execute it to unlock the table
      		$unlock->Execute( );
      	}
      }
      ?>
      

        Okay, It looks like you are crossing examples.

        Your CLockTableCmd.php code shows that you are using a DB object (that's what the "$db = DB::connect( $GLOBALS['g_PearDBDSN'] );" line proves). However, your DB.phpfile is setting up a basic connection with NO object.

        If you got this example from a book, you'll need to check the book for the proper DB.php file. It should have something like:

        <?php // DB.php
        class DB
        {
           ...
           function connect($dbData)
           { ... return $db; }
           function isError($db)
           { ... }
           function Query($query)
           { ... }
           ...
        }
        

          I see, well thats where i made my own db.php

          The book makes no reference to db.php except that it exists, nothing about that gos in it etc...

          Does this pos a big problem?

          Book : http://www.amazon.com/PHP-Game-Programming-Matt-Rutledge/dp/159200153X

          He uses Command prompt to exec all his commands, would he have used an older version of php to create the db.php automaticly?

          Example:

          C:> cd\mysql\scripts
          C:> mysql_install_db
          C:> cd\mysql\bin
          C:> mysqld_safe -user=mysql &

            5 days later

            I'm kind of new to this and this might be totally obvious, but do your have the PEAR DB module installed on your server?

            Just a thought. Maybe it will help you out.

              Write a Reply...