Jump to content

Query statement using a function call


valency

Recommended Posts

Can someone help interpret this for me:

function totalNumof Invoices()

{

$sql = 'SELECT count(id) as total FROM '.$this->dbconnect->getTablePrefix().'invoices '.$where;

      $rsx = $this->dbconnect->querySelect($sql);

}

 

 

how does a query like this work exactly? seems like old php version to me...help explain the getTablePrefix().'invoices '.$where part....

 

the only thing declared in this frankinstein code is this:

function Invoices()

{

 

$this->dbconnect->setTablePrefix($tp);

$tableprefix = $tp;

 

}

Link to comment
https://forums.phpfreaks.com/topic/115311-query-statement-using-a-function-call/
Share on other sites

The purpose of the tableprefix looks to be allowing for mutliple versions of the tables in question to be able to coexist, via the "tableprefix" variable.  This has to have been saved somewhere and is probably brought in via a config or ini file.

 

So when the db was created, rather than have an "invoices" table in the database, the table is actually names 'myinvoices' (assuming that the value returned by the getTablePrefix() method was "my".

 

All that's happening is basic concatention of a string to create the SQL statement that is ultimately being executed.  The $where variable seems to be a global, or it must not be working, so I'd agree if that's true that the design of this isn't the best, as relying on globals is a pretty poor practice. 

 

However, this observation is based on your snippet, and if you omitted things it might not be relevant.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.