Jump to content

Recommended Posts

Fatal error: Call to a member function qstr() on a non-object in C:\xampp\htdocs\ipod\functions.php on line 14

 

 

<?php
require_once('config.php');

function checkwork()
{
header("location: underwork.php");
	echo 'Sorry we are under going work ';
}

function get_username ( $id )
{
	global $db;

	$query = "SELECT `login` FROM `" . DBPREFIX . "members` WHERE `member_id` = " . $db->qstr ( $id );

	if ( $db->RecordCount ( $query ) == 1 )
	{
		$row = $db->getRow ( $query );

		return $row->login;
	}
	else {
		return FALSE;
	}
}	

?>

 

this being line 14

$query = "SELECT `login` FROM `" . DBPREFIX . "members` WHERE `member_id` = " . $db->qstr ( $id );

 

$db is not an object. Probably null/undefined.

Include whatever file that defines $db.

 

 

Unless there's some OOP magic going on. Which is impossible to tell with that code snippet and total lack of explanation of anything.

i do have a class for it

but all it dose is echo about almost everything

dbh = @mysql_connect($dbhost,$dbuser,$dbpassword); if ( ! $this->dbh ) { $this->print_error("
Error establishing a database connection!
Are you sure you have the correct user/password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
"); } $this->select($dbname); } // ================================================================== //	Select a DB (if another one needs to be selected) function select($db) { if ( !@mysql_select_db($db,$this->dbh)) { $this->print_error("
Error selecting database $db!
Are you sure it exists?
Are you sure there is a valid database connection?
"); } } // ================================================================== //	Print SQL/DB error. function print_error($str = "") { if ( !$str ) $str = mysql_error(); // If there is an error then take note of it print "
"; print "SQL/DB Error -- "; print "[$str]"; print "
";	 } // ================================================================== //	Basic Query	- see docs for more detail function query($query, $output = OBJECT) { // Log how the function was called $this->func_call = "\$

 

 

connection.php

<?

define("EZSQL_VERSION","5.1.41");
define("OBJECT","OBJECT",true);
define("ARRAY_A","ARRAY_A",true);
define("ARRAY_N","ARRAY_N",true);


class db {


	function db($dbuser, $dbpassword, $dbname, $dbhost)
	{

		$this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);

		if ( ! $this->dbh )
		{
			$this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?</ol>");
		}


		$this->select($dbname);

	}		
	function select($db)
	{
		if ( !@mysql_select_db($db,$this->dbh))
		{
			$this->print_error("<ol><b>Error selecting database <u>$db</u>!</b><li>Are you sure it exists?<li>Are you sure there is a valid database connection?</ol>");
		}
	}

	// ==================================================================
	//	Print SQL/DB error.

	function print_error($str = "")
	{

		if ( !$str ) $str = mysql_error();

		// If there is an error then take note of it
		print "<blockquote><font face=arial size=2 color=ff0000>";
		print "<b>SQL/DB Error --</b> ";
		print "[<font color=000077>$str</font>]";
		print "</font></blockquote>";	
	}


	function query($query, $output = OBJECT) 
	{

		$this->func_call = "\$db->query(\"$query\", $output)";		

		$this->last_result = null;
		$this->col_info = null;
		$this->last_query = $query;
		$this->result = mysql_query($query,$this->dbh);

		if ( mysql_error() ) 
		{				
			$this->print_error();
			return FALSE;	
		}
		else {


			if ( $this->result )
			{


				$i=0;
				while ($i < @mysql_num_fields($this->result))
				{
					$this->col_info[$i] = @mysql_fetch_field($this->result);
					$i++;
				}


				$i=0;
				while ( $row = @mysql_fetch_object($this->result) )
				{ 


					$this->last_result[$i] = $row;

					$i++;
				}

				@mysql_free_result($this->result);
			}

			return TRUE;

		}
	}


	function RecordCount ( $query )
	{
		return mysql_num_rows ( mysql_query ( $query ) );
	}


	function Mresult ( $query, $a, $b )
	{
		return mysql_result ( mysql_query ( $query ), $a, $b );
	}



	function qstr ( $string, $magic_quotes = false )
	{
		if (!$magic_quotes) {
			if (strnatcmp(PHP_VERSION, '5.3.1') >= 0) {
				return "'" . mysql_real_escape_string($string) . "'";
			}
			$string = str_replace("'", "\\'" , str_replace('\\', '\\\\', str_replace("\0", "\\\0", $string)));
			return  "'" . $string . "'"; 
		}
		return "'" . str_replace('\\"', '"', $string) . "'";
	}


	function get_var($query=null,$x=0,$y=0)
	{


		$this->func_call = "\$db->get_var(\"$query\",$x,$y)";


		if ( $query )
		{
			$this->query($query);
		}


		if ( $this->last_result[$y] )
		{
			$values = array_values(get_object_vars($this->last_result[$y]));
		}

		return $values[$x]?$values[$x]:null;
	}


	function getRow($query=null,$y=0,$output=OBJECT)
	{

		$this->func_call = "\$db->getRow(\"$query\",$y,$output)";

		if ( $query )
		{
			$this->query($query);
		}

		if ( $output == OBJECT )
		{
			return $this->last_result[$y]?$this->last_result[$y]:null;
		}
		elseif ( $output == ARRAY_A )
		{
			return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null;	
		}
		elseif ( $output == ARRAY_N )
		{
			return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null;
		}
		else
		{
			$this->print_error(" \$db->getRow(string query,int offset,output type) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N ");	
		}

	}

	function get_col($query=null,$x=0)
	{

		if ( $query )
		{
			$this->query($query);
		}

		for ( $i=0; $i < count($this->last_result); $i++ )
		{
			$new_array[$i] = $this->get_var(null,$x,$i);
		}

		return $new_array;
	}


	function get_results($query=null, $output = OBJECT)
	{

		$this->func_call = "\$db->get_results(\"$query\", $output)";

		if ( $query )
		{
			$this->query($query);
		}		

		if ( $output == OBJECT )
		{
			return $this->last_result; 
		}
		elseif ( $output == ARRAY_A || $output == ARRAY_N )
		{
			if ( $this->last_result )
			{
				$i=0;
				foreach( $this->last_result as $row )
				{

					$new_array[$i] = get_object_vars($row);

					if ( $output == ARRAY_N )
					{
						$new_array[$i] = array_values($new_array[$i]);
					}

					$i++;
				}

				return $new_array;
			}
			else
			{
				return null;	
			}
		}
	}


	function get_col_info($info_type="name",$col_offset=-1)
	{

		if ( $this->col_info )
		{
			if ( $col_offset == -1 )
			{
				$i=0;
				foreach($this->col_info as $col )
				{
					$new_array[$i] = $col->{$info_type};
					$i++;
				}
				return $new_array;
			}
			else
			{
				return $this->col_info[$col_offset]->{$info_type};
			}

		}

	}


	function vardump($mixed)
	{

		echo "<blockquote><font color=000090>";
		echo "<pre><font face=arial>";

		if ( ! $this->vardump_called )
		{
			echo "<font color=800080><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Variable Dump..</b></font>\n\n";
		}

		print_r($mixed);	
		echo "\n\n<b>Last Query:</b> ".($this->last_query?$this->last_query:"NULL")."\n";
		echo "<b>Last Function Call:</b> " . ($this->func_call?$this->func_call:"None")."\n";
		echo "<b>Last Rows Returned:</b> ".count($this->last_result)."\n";
		echo "</font></pre></font></blockquote>";
		echo "\n<hr size=1 noshade color=dddddd>";

		$this->vardump_called = true;

	}


	function dumpvars($mixed)
	{
		$this->vardump($mixed);	
	}


	function debug()
	{

		echo "<blockquote>";

		if ( ! $this->debug_called )
		{
			echo "<font color=800080 face=arial size=2><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Debug..</b></font><p>\n";
		}
		echo "<font face=arial size=2 color=000099><b>Query --</b> ";
		echo "[<font color=000000><b>$this->last_query</b></font>]</font><p>";

			echo "<font face=arial size=2 color=000099><b>Query Result..</b></font>";
			echo "<blockquote>";

		if ( $this->col_info )
		{


			echo "<table cellpadding=5 cellspacing=1 bgcolor=555555>";
			echo "<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>";


			for ( $i=0; $i < count($this->col_info); $i++ )
			{
				echo "<td nowrap align=left valign=top><font size=1 color=555599 face=arial>{$this->col_info[$i]->type} {$this->col_info[$i]->max_length}<br><font size=2><b>{$this->col_info[$i]->name}</b></font></td>";
			}

			echo "</tr>";


		if ( $this->last_result )
		{

			$i=0;
			foreach ( $this->get_results(null,ARRAY_N) as $one_row )
			{
				$i++;
				echo "<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>$i</font></td>";

				foreach ( $one_row as $item )
				{
					echo "<td nowrap><font face=arial size=2>$item</font></td>";	
				}

				echo "</tr>";				
			}

		} 
		else
		{
			echo "<tr bgcolor=ffffff><td colspan=".(count($this->col_info)+1)."><font face=arial size=2>No Results</font></td></tr>";			
		}

		echo "</table>";		

		} 
		else
		{
			echo "<font face=arial size=2>No Results</font>";			
		}

		echo "</blockquote></blockquote><hr noshade color=dddddd size=1>";


		$this->debug_called = false;
	}


}

?>

 

yeah but i still don't know what that is tho

 

the OOP magic

 

I don't think he meant anything in particular, AFAIK it doesn't mean anything, except that OOP can be a bit mysterious and confusing how it works sometimes especially if you're new.

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.