Sasuun Posted August 27, 2006 Share Posted August 27, 2006 I'm getting the following error whenever I try to execute a query using my db class.[code]No Database Selectedpwned[/code]I have no idea why this is happening because I know for a fact a database is being selected and I've tried seeing if there were any connection errors, but nothing worked. I'm hoping someone else's input can help me solve this problem[b]db_mysql.php[/b][code]class db_mysql{ public $connection = ''; protected $db = ''; public $query_id = ''; public $cur_query = ''; public $error = ''; public $query_count = '0'; public $row = ''; function __construct() { global $INFO; //------------------------------------------------ // do we want to make a persistant db connection //------------------------------------------------ $this->connection = mysql_connect($host,$user,$pass); mysql_select_db($db,$this->connection); //------------------------------------------------ // setup our sql prefix //------------------------------------------------ if ( ! defined( 'SQL_PREFIX' )) { define ( 'SQL_PREFIX', $INFO['dbprefix']); } } public function dbconnect($host,$user,$pass,$db) { $this->connection = mysql_connect($host,$user,$pass); mysql_select_db($db,$this->connection); } public function do_query( $query = '') { if ($query == '') { $query = $this->cur_query; } if ( SQL_PREFIX != "xms_" ) { $query = preg_replace("/\sxms_(\S+?)([\s\.,]|$)/", " ".SQL_PREFIX."\\1\\2", $query); } $this->query_id = mysql_query($query) or die(mysql_error() . "<br />pwned"); echo $this->query_id; $this->query_count++; } public function fetch_row( $ci = '') { if ( $ci == '') { $ci = $this->query_id; } $this->row = mysql_fetch_array( $ci ); return $this->row; $this->row = ''; } public function simple_construct( $q ) { if ( $q['SELECT'] ) { $this->construct_select( $q['SELECT'], $q['FROM'], &$q['WHERE'] ); } elseif ( $q['UPDATE']) { $this->construct_update( $q['UPDATE'], $q['SET'], &$q['WHERE'] ); } elseif ( $q['DELETE']) { $this->construct_delete( $q['DELETE'], $q['WHERE'] ); } elseif ( $q['INSERT']) { $this->construct_insert( $q['INSERT'], $q['FIELDS'], $q['VALUES']); } if ( @$q['ORDER'] ) { $this->construct_order( &$q['ORDER'] ); } if ( $q['LIMIT']) { $this->construct_limit( &$q['LIMIT']); } if ( !$q) { $this->cur_query = ''; } if ($this->cur_query != '') { $this->do_query(); $this->cur_query = ''; } } public function construct_insert( $insert, $fields, $values ) { $this->cur_query = "INSERT INTO $insert ($fields) VALUES($values)"; } public function construct_select( $select, $from, $where = "" ) { $this->cur_query = "SELECT " . $select . " FROM " . SQL_PREFIX . $from; if ($where != "") { $this->cur_query .= "WHERE " . $where; } } public function construct_update( $update, $set, $where) { $this->cur_query = "UPDATE " . SQL_PREFIX . $update . "SET " . $set; if ( $where ) { $this->cur_query .= "WHERE " . $where; } } public function construct_delete( $delete, $where) { $this->cur_query = "DELETE FROM " . SQL_PREFIX . $delete; if ( $where ) { $this->cur_query .= "WHERE $where"; } } public function construct_order( $order ) { $this->cur_query .= "ORDER BY $order"; } public function construct_limit( $limit ) { $this->cur_query .= " LIMIT $limit"; } public function num_rows( $ci = '' ) { if ( $ci = '' ) { $ci = $this->query_id; } return mysql_num_rows( $ci ); } public function get_query_count() { return $this->query_count; }}[/code] Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted August 27, 2006 Share Posted August 27, 2006 You have the following:function __construct(){...$this->connection = mysql_connect($host,$user,$pass);mysql_select_db($db,$this->connection...}How does the constructer get the variables? shouldn't you have something like __construct($var='something', $var2='something') { ... }Sorry if i got it wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.