api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SqlServerTest.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Mevdschee\PhpCrudApi\Tests;
  3. class SqlServerTest extends Tests
  4. {
  5. /**
  6. * Gets the name of the database engine
  7. *
  8. * @return string Name of the database engine
  9. */
  10. public function getEngineName()
  11. {
  12. return 'SQLServer';
  13. }
  14. /**
  15. * Connects to the Database
  16. *
  17. * @return object Database connection
  18. */
  19. public function connect($config)
  20. {
  21. $connectionInfo = array(
  22. 'UID' => $config['username'],
  23. 'PWD' => $config['password'],
  24. 'Database' => $config['database'],
  25. 'CharacterSet' => 'UTF-8',
  26. );
  27. $db = sqlsrv_connect($config['hostname'], $connectionInfo);
  28. if (!$db) {
  29. die("Connect failed: ".print_r(sqlsrv_errors(), true));
  30. }
  31. return $db;
  32. }
  33. /**
  34. * Disconnects from the Database
  35. *
  36. * @return boolean Success
  37. */
  38. public function disconnect($db)
  39. {
  40. return sqlsrv_close($db);
  41. }
  42. /**
  43. * Checks the version of the Database
  44. *
  45. * @return void
  46. */
  47. public function checkVersion($db)
  48. {
  49. $major = 11;
  50. $minor = 0;
  51. $build = 3000;
  52. $version = sqlsrv_server_info($db);
  53. $v = explode('.', $version['SQLServerVersion']);
  54. if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor) || ($v[0]==$major && $v[1]==$minor && $v[2]<$build)) {
  55. die("Detected SQL Server $v[0].$v[1].$v[2], but only $major.$minor.$build and up are supported\n");
  56. }
  57. }
  58. /**
  59. * Gets the capabilities of the Database
  60. *
  61. * @return int Capabilites
  62. */
  63. public function getCapabilities($db)
  64. {
  65. $capabilities = 0;
  66. $capabilities |= self::JSON;
  67. $capabilities |= self::GIS;
  68. return $capabilities;
  69. }
  70. /**
  71. * Seeds the database for this connection
  72. *
  73. * @return void
  74. */
  75. public function seedDatabase($db, $capabilities)
  76. {
  77. $fixture = __DIR__.'/data/blog_sqlserver.sql';
  78. $contents = file_get_contents($fixture);
  79. $queries = preg_split('/\n\s*GO\s*\n/', $contents);
  80. array_pop($queries);
  81. foreach ($queries as $i=>$query) {
  82. if (!sqlsrv_query($db, $query)) {
  83. $i++;
  84. die("Loading '$fixture' failed on statemement #$i with error:\n".print_r(sqlsrv_errors(), true)."\n");
  85. }
  86. }
  87. }
  88. }