Jump to content

Mysql Database Class


barkster

Recommended Posts

I am trying to use this db class here http://www.micahcarrick.com/v2/content/view/3/26/ and I get cannot modify header information when I try and use the class for login.  I've stripped everything out of th the class that I would think would send header and still get the error.  Throws error when I try and redirect the user.

 

<?php 
if($_POST['blogin']) {
require_once('bb.db.class.php');
$db = new db_class;
if (!$db->connect("localhost", "user", "pw", "db", true)){
	echo("Could not connect to database");
	die();
}
$r = $db->select_two("SELECT UserID, Username FROM Users WHERE Username='" . $_POST['tbusername']. "' AND Password='".$_POST['tbpassword']."' AND Banned='0'");
if($r) {
	$userid = $r[0];
	$username = $r[1];
	echo $userid;
	echo $username;
	$_SESSION['UserID']=$userid;
	$_SESSION['Username']=$username;
	header("Location: Success.php");
	die();
} else {
	$msg = "We could not verify your login information, please try again";
}
}
?>

 

stripped class

<?php
define('MYSQL_TYPES_NUMERIC', 'int real ');
define('MYSQL_TYPES_DATE', 'datetime timestamp year date time ');
define('MYSQL_TYPES_STRING', 'string blob ');

class db_class {

   var $last_error;         // holds the last error. Usually mysql_error()
   var $last_query;         // holds the last query executed.
   var $row_count;          // holds the last number of rows from a select
   
   var $host;               // mySQL host to connect to
   var $user;               // mySQL user name
   var $pw;                 // mySQL password
   var $db;                 // mySQL database to select

   var $db_link;            // current/last database link identifier
   var $auto_slashes;       // the class will add/strip slashes when it can
   
   function db_class() {
   
      // class constructor.  Initializations here.
      
      // Setup your own default values for connecting to the database here. You
      // can also set these values in the connect() function and using
      // the select_database() function.
  
      //localhost", "shrinkup_barkste", "bb2828", "shrinkup_shrink
      $this->host = 'localhost';
      $this->user = '';
      $this->pw = '';
      $this->db = ''; 
      $this->auto_slashes = true;
   }

   function connect($host='', $user='', $pw='', $db='', $persistant=true) {

      // Opens a connection to MySQL and selects the database.  If any of the
      // function's parameter's are set, we want to update the class variables.  
      // If they are NOT set, then we're giong to use the currently existing
      // class variables.
      // Returns true if successful, false if there is failure.  
      
      if (!empty($host)) $this->host = $host; 
      if (!empty($user)) $this->user = $user; 
      if (!empty($pw)) $this->pw = $pw; 


      // Establish the connection.
      if ($persistant) 
         $this->db_link = mysql_pconnect($this->host, $this->user, $this->pw);
      else 
         $this->db_link = mysql_connect($this->host, $this->user, $this->pw);

      // Check for an error establishing a connection
      if (!$this->db_link) {
         //$this->last_error = mysql_error();
         return false;
      } 
  
      // Select the database
      if (!$this->select_db($db)) return false;

      return $this->db_link;  // success
   }

   function select_db($db='') {

      // Selects the database for use.  If the function's $db parameter is 
      // passed to the function then the class variable will be updated.

      if (!empty($db)) $this->db = $db; 
      
      if (!mysql_select_db($this->db)) {
         //$this->last_error = mysql_error();
         return false;
      }

      return true;
   }
   
   function select_two($sql) {

      // Performs an SQL query with the assumption that only ONE column and
      // one result are to be returned.
      // Returns the one result.
      
      $r = mysql_query($sql);
      if (!$r) {
         //$this->last_error = mysql_error();
         return false;
      }
      $one = mysql_result($r, 0, 0);
  $two = mysql_result($r, 0, 1);
  $ret = array($one,$two);
      //mysql_free_result($r);
  	return $ret;
   }

} 
?> 

Link to comment
Share on other sites

Yes, I got it to work by copying the class into a new file and making a simpler name.  Never had that happen before, I know what causes it but I couldn't figure out what was going on here.  There must have been something goofy in the file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.