2013-05-17 149 views
0

我有一个简单的“即将推出”页面,我在其中订阅了我打算插入到mysql数据库中的订阅电子邮件。获取'Class PDO not found'错误

我以前运行过代码,但现在在1-2周后回来,似乎有一些问题。

基本上只涉及2个文件:index.htmlsubscribe.phpindex.html是实际“预购页面,并呼吁subscribe.php实际插入电子邮件进入数据库,提供了一个有效的电子邮件,是不是重复,等等。

subscribe.php的代码如下所示。它是一个非常简单的代码。

难道这不是以前的工作!但是现在,似乎是一个“类PDO没有发现......”在这里被使用PDO行未来的错误:

<?php 

function isValidEmail($email = null) 
{ 
    return preg_match("/^ 
    [\d\w\/+!=#|$?%{^&}*`'~-] 
    [\d\w\/\.+!=#|$?%{^&}*`'~-]*@ 
    [A-Z0-9] 
    [A-Z0-9.-]{0,61} 
    [A-Z0-9]\. 
    [A-Z]{2,6}$/ix", $email); 
} 

try { 
    // Connect to the SQLite Database. 
    $db = new PDO('mysql:host=hostnamehere;dbname=dbnamehere', 'usernamehere', 'passwordhere'); 
} catch(Exception $e) { 
    die('connection_unsuccessful'); 
} 

/* Check if table exists */ 
$db->exec('CREATE TABLE IF NOT EXISTS subscribers (email VARCHAR(255), time VARCHAR(255))'); 

/* Check if email has been posted */ 
if (isset($_POST['email'])) { 

    /* Validate email */ 
    if (isValidEmail($_POST['email'])) { 

     /* Check for duplication */ 
     $query = $db->prepare('SELECT COUNT(*) AS count FROM subscribers WHERE email = :email'); 
     $query->execute(array(':email' => $_POST['email'])); 
     $result = $query->fetch(); 

     if ($result['count'] == 0) { // E-mail is unique. 

      $query = $db->prepare('INSERT INTO subscribers (email, time) VALUES (:email, :time)'); 
      $query->execute(array('email' => $_POST['email'], 'time' => date('Y-m-d H:i:s'))); 

      /* Send mail notification */ 
      $to = '[email protected]'; // Email notified of the new subscription 
      $subject = 'New subscriber'; 
      $message = 'Hi, you have one new subscriber. This is his/her e-mail address: ' . $_POST['email'] . '.'; 
      $headers = "From:" . $_POST['email']; 
      mail($to,$subject,$message,$headers); 

      echo 'successful'; 

     } else { // E-mail is already being used. 
      echo 'already_subscribed'; 
     } 

    } else { 
     echo 'invalid_email'; 
    } 

} 
+2

1.什么版本的PHP? 2.有没有名称空间? '\ PDO'会发生什么? –

回答

3

大概PDO是在php.ini中禁用,只启用它。确保你有那里

extension=pdo.so 
extension=pdo_mysql.so 
+0

修复它,谢谢! – Ahmad