Hello I have method let's say that checks if row exists:
/**
* Method rowExists
*
* Checks if row exists with given parameters.
*
* @param name The name of the value in a column.
* @param column The name of the given column.
* @param table The name of the given table.
**/
private function rowExists($name, $column, $table)
{
$this->user = $this->pdo->prepare("SELECT * FROM ".$table." WHERE ".$column." = :name");
$this->user->execute(array(":name" => $name));
if ($this->user->rowCount() > 0)
{
return true;
}
else
{
return false;
}
}
With this I can check if row exists
Usage:
if ($this->rowExistsAnd($this->get['user_id'], $generatedCode, 'user_id', 'generated_code', 'account_verifications') === true) {
Now what I am asking for, this method only supports 1 parameter for checking
What if I want to check WHERE two columns?
Example:
Current query it does:
SELECT * FROM table WHERE column1 = value1
I want:
SELECT * FROM table WHERE column1 = value1 AND column2 = value2
I want to do so with 1 method, without creating another method with adding parameters. How can I do this?
Edit:
private function rowDoesExist($params)
{
if (count($params) < 4)
{
$this->user = $this->pdo->prepare("SELECT * FROM ".$params[0]." WHERE ".$params[1]." = :name");
$execute = array(":name" => $params[2]);
}
else
{
$this->user = $this->pdo->prepare("SELECT * FROM ".$params[0]." WHERE ".$params[1]." = :name AND ".$params[2]." = :name2");
$execute = array(":name" => $params[3], ":name2" => $params[4]);
}
$this->user->execute($execute));
}
Usage:
$this->rowDoesExist(array('users', 'user_name', $username);