Advertisement
Guest User

Untitled

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