私は初心者の PHP プログラマーで、数日前まで PDO について聞いたことがありませんでした。これまでは、自分の Web サイトで PHP のデフォルトの MySQL 関数を使用していましたが、読んでいる限りでは、本当に PDO に切り替える必要があるようです。
PDOを有効にしてApacheを再コンパイルしましたが、次のコードで接続しようとすると:
try
{
$dbh = new PDO('mysql:host=localhost;dbname=' . $dbname, $user, $pass);
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
エラーが発生します:
Error!: could not find driver
phpinfo() を実行したところ、PDO に関連する次のことがわかりました。
'./configure' '--disable-fileinfo' '--disable-phar' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-sqlite=shared' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr'
PDO
PDO support enabled
PDO drivers sqlite, sqlite2
pdo_sqlite
PDO Driver for SQLite 3.x enabled
SQLite Library 3.7.7.1
PDO を機能させるにはどうすればよいですか?
ご協力いただきありがとうございます!