/dialup_admin/lib/sql/drivers/dbx/functions.php

https://github.com/artisdom/freeradius-server · PHP · 146 lines · 126 code · 16 blank · 4 comment · 19 complexity · 460f541f0207651d495be116707f3742 MD5 · raw file

  1. <?php
  2. function da_sql_limit($limit,$point,$config)
  3. {
  4. switch($point){
  5. case 0:
  6. return '';
  7. case 1:
  8. return '';
  9. case 2:
  10. return "LIMIT $limit";
  11. }
  12. }
  13. function da_sql_host_connect($server,$config)
  14. {
  15. if ($config[sql_use_http_credentials] == 'yes'){
  16. global $HTTP_SERVER_VARS;
  17. $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
  18. $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
  19. }
  20. else{
  21. $SQL_user = $config[sql_username];
  22. $SQL_passwd = $config[sql_password];
  23. }
  24. // FIXME: This function is still Postgres specific. Needs to be configurable.
  25. return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
  26. "$SQL_user", "$SQL_passwd", DBX_PERSISTENT);
  27. }
  28. function da_sql_connect($config)
  29. {
  30. if ($config[sql_use_http_credentials] == 'yes'){
  31. global $HTTP_SERVER_VARS;
  32. $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
  33. $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
  34. }
  35. else{
  36. $SQL_user = $config[sql_username];
  37. $SQL_passwd = $config[sql_password];
  38. }
  39. // FIXME: This function is still Postgres specific. Needs to be configurable.
  40. return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
  41. "$SQL_user", "$SQL_passwd");
  42. }
  43. function da_sql_pconnect($config)
  44. {
  45. if ($config[sql_use_http_credentials] == 'yes'){
  46. global $HTTP_SERVER_VARS;
  47. $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
  48. $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
  49. }
  50. else{
  51. $SQL_user = $config[sql_username];
  52. $SQL_passwd = $config[sql_password];
  53. }
  54. // FIXME: This function is still Postgres specific. Needs to be configurable.
  55. return @dbx_connect(DBX_PGSQL, "$server", "$config[sql_database]",
  56. "$SQL_user", "$SQL_passwd", DBX_PERSISTENT);
  57. }
  58. function da_sql_close($link,$config)
  59. {
  60. @dbx_close($link);
  61. }
  62. function da_sql_escape_string($string)
  63. {
  64. return addslashes($string);
  65. }
  66. function da_sql_query($link,$config,$query)
  67. {
  68. if ($config[sql_debug] == 'true') {
  69. print "<b>DEBUG(SQL,PG DRIVER): Query: <i>$query</i></b><br>\n";
  70. }
  71. return @dbx_query($link,$query);
  72. }
  73. function da_sql_num_rows($result,$config)
  74. {
  75. if ($config[sql_debug] == 'true')
  76. print "<b>DEBUG(SQL,PG DRIVER): Query Result: Num rows:: " . $result->rows . "</b><br>\n";
  77. return $result->rows;
  78. }
  79. $dbx_global_record_counter = array() ;
  80. function da_sql_fetch_array($result,$config)
  81. {
  82. global $dbx_global_record_counter;
  83. if (!$dbx_global_record_counter[$result->handle]){
  84. $dbx_global_record_counter[$result->handle] = 0;
  85. }
  86. if ($dbx_global_record_counter[$result->handle] <= $result->rows - 1 ){
  87. return $result->data[$dbx_global_record_counter[$result->handle]++];
  88. } elseif ($dbx_global_record_counter[$result->handle] > $result->rows - 1 ) {
  89. $dbx_global_record_counter[$result->handle]++;
  90. return NULL;
  91. } else {
  92. $dbx_global_record_counter[$result->handle]++;
  93. return FALSE;
  94. }
  95. }
  96. function da_sql_affected_rows($link,$result,$config)
  97. {
  98. // FIXME: This function is still Postgres specific.
  99. if ($config[sql_debug] == 'true')
  100. print "<b>DEBUG(SQL,PG DRIVER): Query Result: Affected rows:: " . @pg_cmdtuples($result->handle) . "</b><br>\n";
  101. return @pg_cmdtuples($result->handle);
  102. }
  103. function da_sql_list_fields($table,$link,$config)
  104. {
  105. $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;");
  106. if ($res){
  107. $fields[num] = $res->cols;
  108. }
  109. $res = @dbx_query($link,"SELECT * FROM ".$table." LIMIT 1 ;");
  110. if ($res)
  111. $fields[res] = $res->info[name];
  112. else
  113. return NULL;
  114. return $fields;
  115. }
  116. function da_sql_num_fields($fields,$config)
  117. {
  118. if ($fields)
  119. return $fields[num];
  120. }
  121. function da_sql_field_name($fields,$num,$config)
  122. {
  123. if ($fields)
  124. return $fields[res][$num];
  125. }
  126. function da_sql_error($link,$config)
  127. {
  128. return dbx_error($link);
  129. }
  130. ?>