Permalink
Browse files

Added support for mysql

  • Loading branch information...
1 parent 388cb56 commit a059f57eff45a2f8567cac92b28f6c23241b4844 @rodneyshupe rodneyshupe committed Nov 14, 2010
Showing with 49 additions and 21 deletions.
  1. +23 −1 default-config.php
  2. +26 −20 xbmcjsonlib.php
View
24 default-config.php
@@ -2,7 +2,29 @@
// enter hostname and port of the xbmc json service here. By default 8080
$xbmcjsonservice = "http://USER:PASSWORD@localhost:8080/jsonrpc"; //remove 'USER:PASSWORD@' if your xbmc install does not require a password.
$xbmcimgpath = '/vfs/'; //leave as default if unsure
-$xbmcdbpath = 'sqlite:/home/xbmc/.xbmc/userdata/Database/';
+
+$xbmcdbconn = array(
+ 'video' => array('dns' => 'sqlite:/home/xbmc/.xbmc/userdata/Database/MyVideos34.db', 'username' => '', 'password' => '', 'options' => array()),
+ 'music' => array('dns' => 'sqlite:/home/xbmc/.xbmc/userdata/Database/MyMusic7.db', 'username' => '', 'password' => '', 'options' => array()),
+ );
+//Example of mysql connections
+/*
+$xbmcdbconn = array(
+ 'video' => array(
+ 'dns' => 'mysql:host=hostname;dbname=videos',
+ 'username' => '',
+ 'password' => '',
+ 'options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
+ ),
+ 'music' => array(
+ 'dns' => 'mysql:host=hostname;dbname=music',
+ 'username' => 'username',
+ 'password' => 'password',
+ 'options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
+ ),
+
+ );
+*/
// enter path to sickbeards's coming episodes page
$sickbeardcomingepisodes = 'http://user:password@COMPUTER:PORT/sickbeard/comingEpisodes/';
View
46 xbmcjsonlib.php
@@ -300,35 +300,41 @@ function sqlquerystring($method, $args = array()) {
}
}
function sqlitetoarray($sql, $dbname, $resultwrapper) {
- global $xbmcdbpath;
+ global $xbmcdbconn;
- if ($dbhandle = new PDO($xbmcdbpath.$dbname)) {
- $dbquery = @$dbhandle->query($sql);
- if ($dbquery === false) {
+ if(!empty($xbmcdbconn[$dbname]['dns'])) {
+ if ($dbhandle = new PDO($xbmcdbconn[$dbname]['dns'], $xbmcdbconn[$dbname]['username'], $xbmcdbconn[$dbname]['password'], $xbmcdbconn[$dbname]['options'])) {
+ $dbquery = @$dbhandle->query($sql);
+ if ($dbquery === false) {
+ $dbhandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $error = $dbhandle->errorInfo();
+ if($error[0] != "") {
+ $errCode = (-1 * $error[1]) - 41000;
+ $errMsg = 'Datbase Query Error:'.$error[2];
+ } else {
+ $errCode = -41000;
+ $errMsg = 'Datbase Query Error';
+ }
+ $return = array('error' => array('code' => $errCode, 'message' => $errMsg), 'id' => 0, 'jsonrpc' => '2.0');
+ } else {
+ $results = $dbquery->fetchAll();
+ $return = array('id' => 1, 'jsonrpc' => '2.0', 'result' => array('start' => 0, 'end' => sizeof($results), $resultwrapper => $results ), 'total' => sizeof($results));
+ }
+ } else {
$dbhandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$error = $dbhandle->errorInfo();
if($error[0] != "") {
- $errCode = (-1 * $error[1]) - 41000;
- $errMsg = 'Datbase Query Error:'.$error[2];
+ $errCode = (-1 * $error[1]) - 40000;
+ $errMsg = 'Datbase Connection Error:'.$error[2].' ('.$xbmcdbpath.$dbname.')';
} else {
- $errCode = -41000;
- $errMsg = 'Datbase Query Error';
+ $errCode = -40000;
+ $errMsg = 'Datbase Connection Error: ('.$xbmcdbpath.$dbname.')';
}
$return = array('error' => array('code' => $errCode, 'message' => $errMsg), 'id' => 0, 'jsonrpc' => '2.0');
- } else {
- $results = $dbquery->fetchAll();
- $return = array('id' => 1, 'jsonrpc' => '2.0', 'result' => array('start' => 0, 'end' => sizeof($results), $resultwrapper => $results ), 'total' => sizeof($results));
}
} else {
- $dbhandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $error = $dbhandle->errorInfo();
- if($error[0] != "") {
- $errCode = (-1 * $error[1]) - 40000;
- $errMsg = 'Datbase Connection Error:'.$error[2].' ('.$xbmcdbpath.$dbname.')';
- } else {
- $errCode = -40000;
- $errMsg = 'Datbase Connection Error: ('.$xbmcdbpath.$dbname.')';
- }
+ $errCode = -50000;
+ $errMsg = 'Configuration Error: Check your config.php file.';
$return = array('error' => array('code' => $errCode, 'message' => $errMsg), 'id' => 0, 'jsonrpc' => '2.0');
}
return $return;

0 comments on commit a059f57

Please sign in to comment.