Accessing the CCP DB programmatically/PHP-PDO
From EVEDev
Accessing the CCP DB programmatically using PHP, PDO and connecting in this case to MySQL.
Please see the PDO documentation for other server types, PDO supports many.
Make sure to notice the unicode commands sent to the server once connected.
[edit] Code Example
example.php
<html><head></head><body> <?php try { $nl = "\n"; $db['type'] = 'mysql'; // change to your server type per pdo docs $db['host'] = 'localhost'; // change to your database server $db['user'] = 'username'; // change to your database username $db['pass'] = 'password'; // change to your database user password $db['schema'] = 'mydatabase'; // change to your database name $dbh = new PDO($sw_db['type'].':host='.$sw_db['host'].';dbname='.$sw_db['schema'], $sw_db['user'], $sw_db['pass']); // the SSD is in unicode, so to avoid seeing weird characters when displaying text fields to the user, make sure our connection is transfering unicode // no dash in utf8, this may be mysql specific $dbh->exec('SET NAMES utf8'); $dbh->exec('SET CHARACTER SET utf8'); // a sample query $sql = 'SELECT `t1`.`factionName` AS `name` FROM `chrFactions` AS `t1` ORDER BY `t1`.`factionName` ASC'; $sth = $dbh->prepare($sql); if (!$sth->execute()) throw new PDOException('execute'); $ret = $sth->fetchAll(PDO::FETCH_ASSOC); if (empty($ret)) // if no results is an error throw new PDOException('no results'); // do something with the data here var_dump($ret); } catch (PDOException $e) { echo '<h2>Database error</h2>'.$nl; echo '<p>Message: '.$e->getMessage(). '</p>'.$nl; if ($dbh) echo '<p>Info: '.print_r($dbh->errorInfo(), true).'</p>'.$nl; die(); // quit program } ?> </body></html>

