So this works fine
try{
$db = new PDO("mysql:host=localhost;dbname=", '', '');
$db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
echo $e->getMessage();
die();
}
try{
$sql = "UPDATE username SET active = '1' WHERE activecode = :activecode";
$stmt = $db->prepare($sql);
$stmt->bindParam(':activecode', $_GET["activecode"]);
$stmt->execute();
$stmt->rowCount();
if ( $stmt->rowCount() === 1){
echo "Your account is now active";
header( "refresh:10; url=index.php" );
echo "<br><a href='profilesetup.php'>Home page</a>";
$completeActive = "UPDATE username SET activecode = 'Active' WHERE activecode = :activecode";
$setActive = $db->prepare($completeActive);
$setActive->bindParam(':activecode', $_GET["activecode"]);
$setActive->execute();
}
else {
echo "Your account is already active";
// header( "refresh:10; url=index.php" );
echo "<br><a href='index.php'>Home page</a>";
exit;
}
}
catch(Exception $e ) {
echo "Your account is already active";
// header( "refresh:10; url=login.php" );
echo "<br><a href='login.php'>Login page</a>";
exit;
}
?>
This on the other hand dosen't with error Call to undefined method PDO::rowCount()
<?php
date_default_timezone_set("Europe/London");
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
class Database
{
private $host = "localhost";
private $user = "";
private $pass = "";
private $dbname = "";
private $dbh;
private $error;
private $stmt;
public function __construct()
{
//SET DSN
$dsn = "mysql:host=". $this->host . ";dbname=" . $this->dbname;
$options = array
(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE =>PDO::ERRMODE_EXCEPTION
);
//create PDO
try
{
$this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
}
catch(PDOException $e)
{
$this->error = $e->getMessage();
}
}
public function query($query)
{
$this->stmt = $this->dbh->prepare($query);
}
public function bind($param, $value, $type = null)
{
if(is_null($type))
{
switch(true)
{
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($param, $value, $type);
}
public function execute()
{
return $this->stmt->execute();
}
public function lastInsertId()
{
$this->dbh->lastInsertId();
}
public function rowCount()
{
$this->dbh->rowCount();
}
public function resultset()
{
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
<?php
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
require "loadclasses.php";
$database = new Database;
try{
$sql = "UPDATE username SET active = '1' WHERE activecode = :activecode";
$stmt = $database->query($sql);
$database->bind(':activecode', $_GET["activecode"]);
$database->execute();
$database->rowCount();
if ( $stmt->rowCount() === 1){
echo "Your account is now active";
// header( "refresh:10; url=index.php" );
echo "<br><a href='profilesetup.php'>Home page</a>";
$completeActive = "UPDATE username SET activecode = 'Active' WHERE activecode = :activecode";
$setActive = $database->query($completeActive);
$setActive->bindParam(':activecode', $_GET["activecode"]);
$setActive->execute();
}
else {
echo "Your account is already active";
//header( "refresh:10; url=index.php" );
echo "<br><a href='index.php'>Home page</a>";
exit;
}
}
catch(Exception $e ) {
echo "Your account is already active";
//header( "refresh:10; url=login.php" );
echo "<br><a href='login.php'>Login page</a>";
exit;
}
?>