Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

mysql - php code to test pdo is available?

I want to use PDO but I'm not sure whether my hosting has set it up properly.

How can I test, in PHP, whether it is setup and working for MySQL?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

PDO is always installed for php 5.1+. You can check for specific db drivers that are installed or not using phpinfo(); You could try to check for specific drivers using @Mark Baker idea and checking for specific constants;

var_dump(defined(PDO::MYSQL_ATTR_LOCAL_INFILE)); // mysql
var_dump(PDO::FB_ATTR_TIME_FORMAT)); // firebird

Note that not all drivers have specific constants defined so phpinfo() remains best solution.

Using command line you can check using:

$ php -m

As an alternative of phpinfo() you can use:

extension_loaded ('PDO' ); // returns boolean
// or
extension_loaded('pdo_mysql');
// or get all extensions and search for a specific one
get_loaded_extensions(); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...