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

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.