2013-05-17 144 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