api.ubstorage.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * UBkey-value storage API
  4. */
  5. /**
  6. * Sets key=>value in ubstorage
  7. *
  8. * @param string $key
  9. * @param string $value
  10. */
  11. function zb_StorageSet($key, $value) {
  12. $key = mysql_real_escape_string($key);
  13. $value = mysql_real_escape_string($value);
  14. $query_clean = "DELETE from `ubstorage` WHERE `key`='" . $key . "'";
  15. nr_query($query_clean);
  16. $query_create = "INSERT INTO `ubstorage` (`id` ,`key` ,`value`) VALUES (NULL , '" . $key . "', '" . $value . "');";
  17. nr_query($query_create);
  18. }
  19. /**
  20. * Returns value or empty data from ubstorage if key not exists
  21. *
  22. * @param string $key
  23. * @return string
  24. */
  25. function zb_StorageGet($key) {
  26. $key = mysql_real_escape_string($key);
  27. $query = "SELECT `value` from `ubstorage` WHERE `key`='" . $key . "'";
  28. $fetchdata = simple_query($query);
  29. if (!empty($fetchdata)) {
  30. $result = $fetchdata['value'];
  31. } else {
  32. $result = '';
  33. }
  34. return ($result);
  35. }
  36. /**
  37. * Returns array of keys in ubstorage if they contains search pattern
  38. *
  39. * @param string $keypattern
  40. * @return array
  41. */
  42. function zb_StorageFindKeys($keypattern) {
  43. $keypattern = mysql_real_escape_string($keypattern);
  44. $query = "SELECT `key` from `ubstorage` WHERE `key` LIKE '%" . $keypattern . "%'";
  45. $result = simple_queryall($query);
  46. return ($result);
  47. }
  48. /**
  49. * Deletes ubstorage database record by key name
  50. *
  51. * @param string $key
  52. */
  53. function zb_StorageDelete($key) {
  54. $key = mysql_real_escape_string($key);
  55. $query = "DELETE from `ubstorage` WHERE `key`='" . $key . "'";
  56. nr_query($query);
  57. }
  58. ?>