jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_dbsample.php] - Diff between revs 1 and 85

Show entire file Ignore whitespace

Rev 1 Rev 85
Line 4... Line 4...
   
// TARGET dbplug:databasename:username:pass:hostkey // TARGET dbplug:databasename:username:pass:hostkey
   
class WeatherMapDataSource_dbsample extends WeatherMapDataSource { class WeatherMapDataSource_dbsample extends WeatherMapDataSource {
   
  function Init(&$map)
  {
  if(! function_exists("mysql_real_escape_string") ) return FALSE;
  if(! function_exists("mysql_connect") ) return FALSE;
   
  return(TRUE);
  }
   
function Recognise($targetstring) function Recognise($targetstring)
{ {
if(preg_match("/^dbplug:([^:]+):([^:]+):([^:]+):([^:]+)$/",$targetstring,$matches)) if(preg_match("/^dbplug:([^:]+)$/",$targetstring,$matches))
{ {
return TRUE; return TRUE;
} }
else else
{ {
Line 18... Line 26...
} }
} }
   
function ReadData($targetstring, &$map, &$item) function ReadData($targetstring, &$map, &$item)
{ {
if(preg_match("/^dbplug:([^:]+):([^:]+):([^:]+):([^:]+)$/",$targetstring,$matches)) $data[IN] = NULL;
  $data[OUT] = NULL;
  $data_time = 0;
   
  if(preg_match("/^dbplug:([^:]+)$/",$targetstring,$matches))
{ {
$database = $matches[0]; $database_user = $map->get_hint('dbplug_dbuser');
$db_user = $matches[1]; $database_pass = $map->get_hint('dbplug_dbpass');
$db_pass = $matches[2]; $database_name = $map->get_hint('dbplug_dbname');
$key = mysql_real_escape_string($matches[3]); $database_host = $map->get_hint('dbplug_dbhost');
   
  $key = mysql_real_escape_string($matches[1]);
   
$SQL = "select in,out from table where host=$key"; $SQL = "select in,out from table where host=$key LIMIT 1";
} if(mysql_connect($database_host,$database_user,$database_pass))
else {
{ if(mysql_select_db($database_name))
return ( array(-1,-1) ); {
  $result = mysql_query($SQL);
  if (!$result)
  {
  warn("dbsample ReadData: Invalid query: " . mysql_error()."\n");
  }
  else
  {
  $row = mysql_fetch_assoc($result);
  $data[IN] = $row['in'];
  $data[OUT] = $row['out'];
  }
  }
  else
  {
  warn("dbsample ReadData: failed to select database: ".mysql_error()."\n");
  }
  }
  else
  {
  warn("dbsample ReadData: failed to connect to database server: ".mysql_error()."\n");
  }
   
  $data_time = now();
} }
   
   
  debug ("RRD ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
   
  return( array($data[IN], $data[OUT], $data_time) );
} }
} }
   
// vim:ts=4:sw=4: // vim:ts=4:sw=4:
?> ?>

Powered by WebSVN 2.2.1