Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2. //exit(); //Comment this line to have this scripta actually DO anything
  3. //Obviously you'll have to secure access to this script (USING IIS or Apache HTTP authentication)
  4. $host = $_GET['a'];
  5. $user = $_GET['b'];
  6. $pass = $_GET['c'];
  7. $dbname = $_GET['d'];
  8.  
  9. connect($host,$user,$pass,$dbname);
  10.  
  11. $sql = array();
  12. $sql['list tables'] = '
  13. SELECT TABLE_SCHEMA,TABLE_NAME, OBJECTPROPERTY(object_id(TABLE_NAME), N\'IsUserTable\') AS type
  14. FROM INFORMATION_SCHEMA.TABLES';
  15.  
  16. $tables = getObjects($sql['list tables']);
  17.  
  18. header('content-type: text/xml');
  19. $document = new SimpleXMLElement('<dump><tables></tables></dump>');
  20.  
  21. foreach($tables as $table) {
  22. $dump = getArray('SELECT * FROM '.$table->TABLE_SCHEMA.'.'.$table->TABLE_NAME);
  23.  
  24. $newTable = $document->tables[0]->addChild('table');
  25. $newTable->addAttribute('name',$table->TABLE_NAME);
  26. foreach($dump as $dumpRow) {
  27. $newRow = $newTable->addChild('row');
  28. foreach($dumpRow as $field=>$value) {
  29. $safe_value = preg_replace('/&(?!\w+;)/', '&', $value);
  30. $newRow->addChild($field,$safe_value);
  31. }
  32. }
  33. }
  34.  
  35.  
  36. echo $document->asXML();
  37.  
  38.  
  39. function connect($host,$user,$pass,$dbname)
  40. {
  41. mssql_connect($host,$user,$pass);
  42. mssql_select_db($dbname);
  43. }
  44.  
  45.  
  46. /**
  47. * Get the database results as a object array
  48. * @param $query string SQL Query
  49. */
  50. function getObjects($query)
  51. {
  52. $res = mssql_query($query);
  53. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  54. return array();
  55. }
  56. $rows = array();
  57. while($row = mssql_fetch_object($res)) {
  58. $rows[] = $row;
  59. }
  60. return $rows;
  61. }
  62.  
  63. /**
  64. * Get the database results as an array
  65. * @param $query string SQL Query
  66. */
  67. function getArray($query)
  68. {
  69. $res = mssql_query($query);
  70. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  71. return array();
  72. }
  73. $rows = array();
  74. while($row = mssql_fetch_assoc($res)) {
  75. $rows[] = $row;
  76. }
  77. return $rows;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement