Oh noez, get out; It's an l33t person with skillz y'know br0
Printable View
Oddly. I understand all of this code.
This is just c# to me so i guess i could help mwhaha. But let me learn some basics of PHP.
I know the variables are auto assigned just reminds me of the var function in C#.
Any how this looks good seems you have your own Query classes which is pretty neat to.
I wonder if there interfaces in PHP hmm.. time for google.
Any how good luck! With your development. I'm sure it will be even better and good as just as this User class.
Edit
interface iTemplate
{
public function setVariable($name, $var);
public function getHtml($template);
}
I'm so going PHP...
Ported a Interface from C# :OCode:<!-- Compose Mysql Query -->
interface IMySqlComposer
{
<!-- Paramters is a Object array -->
public function executeQuery($Parameters;
<!-- Type is a Type, Parameters is a Object array -->
public function getResultl($Type, $Parameters);
}
Lol :P
You just copied from the manual - PHP: Object Interfaces - Manual
This is like UberCMS, they use guest and user classes
It would make sense to do it that way, so you can easily differentiate which content you'd like to display, depending on the request being made.
Sent from my iPhone 4S using Tapatalk
This looks pretty different from what a lot of people are doing. I do like the way you search if the session keys are set. You could just return false instead of using the variable y in my opinion(from what I skimmed). Nice though.
Nice release but I have some suggestions. I do not understand why you are doing some of the following... like it is really redundant.
That is your constructor, setting the instance variable $iCore to the parameter variable $core. Now in some of your methods you do this:Code:
public function Users( Core $core )
{
$this->iCore = $core;
$this->searchForSessions();
}
...
But you never actually use $core, you use $this->iCore. Just thought you might want to fix that up. You also might want to change the following:Code:
protected function searchForSessions()
{
global $core;
...
Change the 'LEFT JOIN' to 'INNER JOIN' or 'JOIN' (alias).Code:
...
SELECT
u.*, b.expire, b.reason
FROM
users AS u
LEFT JOIN
bans AS b
ON
( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 )
WHERE
u.username = ?
AND
u.password = ?
LIMIT 1;
...
Thank you for repeating me, already sayed...
Go learn the SQL syntax and then come back...Quote:
You also might want to change the following:
Change the 'LEFT JOIN' to 'INNER JOIN' or 'JOIN' (alias).Code:
...
SELECT
u.*, b.expire, b.reason
FROM
users AS u
LEFT JOIN
bans AS b
ON
( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 )
WHERE
u.username = ?
AND
u.password = ?
LIMIT 1;
...
http://img17.imageshack.us/img17/6802/knipseld.png
Joopie your error is a common error that occurs when you do not set the expire column in the database. Take a look and then fix your local settings.
Exhibit 1:
http://oi44.tinypic.com/34ye1wx.jpg
Exhibit 2: (suggested query)
Exhibit 3:Code:
SELECT u.*, b.expire, b.reason
FROM users u
INNER JOIN bans b
ON u.username = b.value
WHERE u.username = ?
AND u.password = ?
AND (UNIX_TIMESTAMP() - b.expire) < 0
ORDER BY b.id DESC
LIMIT 1;
http://oi41.tinypic.com/m73z93.jpg
Lolz, `common error` There is NO ERROR.
There is nothing wrong with LEFT JOIN.
And there should nothing to-be fix /facepalm
...
Go remove yourself form the banlist.
You should see that it doens't work anymore
LEFT JOIN isn't equal to INNER JOIN.
When you have 2 tables
The first table has a row with id 1
And the second row is empty
When you use INNER JOIN like `table1`.`id` = `table2`.`id` you don't get any results.
But if you do LEFT JOIN you still get the row that's in table 1 even if he can't select the row from table 2.
BIG diffrents..
And may be used both as it is a default MySQL function...
*Why making it harder when it can be easily done*
Joopie I am well aware that LEFT JOIN and INNER JOIN or JOIN (alias) are different. It would make no sense to a suggest a change if they meant the same thing. According to the logic and how the query should be structured, INNER JOIN or JOIN (alias) is the appropriate way to handle this.
Go do some research on SQL rather than posting the same thing (your wrong opinion) over and over and over again. It would be a better use of your time.
Ok first I thought you were confused. Now I know you are just out right stupid. I am going to add comments to both queries to make it more like pseudocode. So pay attention.
Original Query:
New Query: (suggested query pseudo)Code:
SELECT u.*, b.expire, b.reason # Selects all the columns from the 'users' table and two columns from the 'bans' table.
FROM users AS u # Choosing the 'users' table to select the columns from. Setting alias 'u'.
LEFT JOIN bans AS b # Loading all the results from the 'bans' table. Setting alias 'b'.
ON ( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 ) # Matching only results from 'users' table that has a username of the 'bans' table value column. Ensuring unix timestamp is not expired (I do not know why he did that check in this part of the query...).
WHERE u.username = ? # Where the username is the first parameter...
AND u.password = ? # ... and the password is the second parameter.
LIMIT 1; # Only display the first returned row from the query.
Code:
SELECT u.*, b.expire, b.reason # Selects all the columns from the 'users' table and two columns from the 'bans' table.
FROM users u # Choosing the 'users' table to select the columns from. Setting alias 'u'.
INNER JOIN bans b # Loading conditional results (condition below). Setting alias 'b'.
ON u.username = b.value # Only grabbing pair matches in both tables, condition is username.
WHERE u.username = ? # Where the username is the first parameter...
AND u.password = ? # ... and the password is the second parameter...
AND (UNIX_TIMESTAMP() - b.expire) < 0 # ... and the unix timestamp minus expiration is less than 0 (expired).
ORDER BY b.id DESC # Order ban results in descending order to get the most recent ban.
LIMIT 0,1; # Only display the first returned row from the query.