收到“找不到PDO类"错误 [英] Getting a 'Class PDO not found' error

查看:58
本文介绍了收到“找不到PDO类"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的即将推出"页面,在该页面上可以订阅要插入到mysql数据库中的电子邮件.

I have a simple 'Coming Soon' page on which I take subscribing emails which I intend to insert into a mysql database.

我以前运行过代码,但是现在在1-2周后又回到了代码上,似乎有一些问题.

I had the code running before, but now coming back to it 1-2 weeks later, there seem to be some problems.

基本上只涉及2个文件:index.htmlsubscribe.php. index.html实际上是即将推出"页面,它调用subscribe.php将电子邮件实际插入数据库中,前提是该电子邮件有效,不是重复的,等等.

Basically there are only 2 files involved: index.html and subscribe.php. index.html is the actually 'Coming Soon' page, and it calls subscribe.php to actually insert the email into database, provided its a valid email, is not a duplicate, etc ..

subscribe.php的代码如下.这真的是一个非常简单的代码.

The code for subscribe.php is given below. Its a very simple code really.

这不是以前起作用的!但是,现在似乎在使用PDO的行出现找不到PDO类..."错误:

Do not that this WAS working before ! However now there seems to be a 'Class PDO not found ...' error coming at the line where PDO is being used:

<?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 = 'newsubscriber@xyz.com'; // 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';
    }

}

推荐答案

可能在您的php.ini中禁用了PDO,只需启用它即可.确保你在那里

Probably the PDO is disabled in your php.ini, just enable it. make sure you have there

extension=pdo.so
extension=pdo_mysql.so

这篇关于收到“找不到PDO类"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆