当我尝试运行它时,PDO类无法返回空白页面?

I've created an email class that will add users to a mysql database. then I've created two methods, the first is private static so I can access it within the second method which is public static, when run this class displays a blank page? What could be the cause of the blank page?

class Email {
private static function DATABASE() {
    $dbh = new PDO("mysql:host=localhost;dbname=emails", 'bjw123nasd4441', 'hj12j2kJKj11s');
    return $dbh;
}
public static function addemail($email) {
    $sqldata = array('email' => $email);
        $stat = Email::DATABASE();
    $stat->prepare("INSERT INTO tasklist (email) VALUES (:email)");
    $stat->execute($sqldata);
    }
}

Email::addemail('foo@bar.com');

I get this error with PHP Display Errors..

Call to undefined method PDO::execute()

you try to directly call pdo->execute(), that won't work. try this:

$stat = self::DATABASE();
$query = $stat->prepare("INSERT INTO tasklist (email) VALUES (:email)");
$query->execute($sqldata);

and you should also just use one pdo instance:

class Email {

    private static $dbh = null;

    private static function DATABASE() {
        if(is_null(self::$dbh))
            self::$dbh = new PDO("mysql:host=localhost;dbname=emails", 'bjw123nasd4441', 'hj12j2kJKj11s');
        return self::$dbh;
    }

    //...

}

I think you receive an FATAL error on this line:

$stat = Task::DATABASE();

Task does not exist? This should be Email::DATABASE();.

I assume you are not showing your errors too, you could attempt setting the following at the top of your script:

error_reporting(E_ALL);
ini_set('display_errors', true);

This should fix your white screen with an clear error.

Sidenote(s)

  1. You instantiate a new database connection on each email you want to add.
  2. I believe an class Email shouldn't be in charge of your database connection.