Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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 = $_SERVER['argv'][1];
  5. $user = $_SERVER['argv'][2];
  6. $pass = $_SERVER['argv'][3];
  7. $dbname = $_SERVER['argv'][4];
  8.  
  9. connect($host,$user,$pass,$dbname);
  10. echo "Connected\n";
  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. echo "GETTINGOBJECT\n";
  17. $tables = getObjects($sql['list tables']);
  18. var_dump($tables);
  19. echo "GETTINGOBJECT DONE\n";
  20. header('content-type: text/plain');
  21. $document = new SimpleXMLElement('<dump><tables></tables></dump>');
  22.  
  23. echo "SIMPLEXML DONE\n";
  24. foreach($tables as $table) {
  25. echo "GETARRAY\n";
  26. $dump = getArray('SELECT * FROM '.$table->TABLE_SCHEMA.'.'.$table->TABLE_NAME);
  27. echo "GETARRAY DONE\n";
  28.  
  29. $newTable = $document->tables[0]->addChild('table');
  30. $newTable->addAttribute('name',$table->TABLE_NAME);
  31. foreach($dump as $dumpRow) {
  32. $newRow = $newTable->addChild('row');
  33. foreach($dumpRow as $field=>$value) {
  34. $safe_value = preg_replace('/&(?!\w+;)/', '&', $value);
  35. $newRow->addChild($field,$safe_value);
  36. }
  37. }
  38. }
  39.  
  40. echo "ASXML\n";
  41. echo $document->asXML();
  42. echo "ASXML DONE\n";
  43.  
  44.  
  45. function connect($host,$user,$pass,$dbname)
  46. {
  47. mssql_connect($host,$user,$pass);
  48. mssql_select_db($dbname);
  49. var_dump(mssql_get_last_message());
  50. }
  51.  
  52.  
  53. /**
  54. * Get the database results as a object array
  55. * @param $query string SQL Query
  56. */
  57. function getObjects($query)
  58. {
  59. $res = mssql_query($query);
  60. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  61. return array();
  62. }
  63. $rows = array();
  64. while($row = mssql_fetch_object($res)) {
  65. $rows[] = $row;
  66. }
  67. return $rows;
  68. }
  69.  
  70. /**
  71. * Get the database results as an array
  72. * @param $query string SQL Query
  73. */
  74. function getArray($query)
  75. {
  76. $res = mssql_query($query);
  77. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  78. return array();
  79. }
  80. $rows = array();
  81. while($row = mssql_fetch_assoc($res)) {
  82. $rows[] = $row;
  83. }
  84. return $rows;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement