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.

MysqlTest.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. require_once(__DIR__ . '/Tests.php');
  3. class MysqlTest extends Tests
  4. {
  5. /**
  6. * Connects to the Database
  7. *
  8. * @return object Database connection
  9. */
  10. public function connect($config)
  11. {
  12. $db = mysqli_connect(
  13. $config['hostname'],
  14. $config['username'],
  15. $config['password'],
  16. $config['database']
  17. );
  18. if (mysqli_connect_errno()) {
  19. die("Connect failed: ".mysqli_connect_error()."\n");
  20. }
  21. mysqli_set_charset($db,'utf8');
  22. return $db;
  23. }
  24. /**
  25. * Disconnects from the Database
  26. *
  27. * @return boolean Success
  28. */
  29. public function disconnect($db)
  30. {
  31. return mysqli_close($db);
  32. }
  33. /**
  34. * Checks the version of the Database
  35. *
  36. * @return void
  37. */
  38. public function checkVersion($db)
  39. {
  40. $major = 5;
  41. $minor = 5;
  42. $version = mysqli_get_server_version($db);
  43. $v = array(floor($version/10000),floor($version/100));
  44. if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
  45. die("Detected MySQL $v[0].$v[1], but only $major.$minor and up are supported\n");
  46. }
  47. }
  48. /**
  49. * Gets the capabilities of the Database
  50. *
  51. * @return int Capabilites
  52. */
  53. public function getCapabilities($db)
  54. {
  55. $capabilities = 0;
  56. $version = mysqli_get_server_version($db);
  57. if ($version>50600) {
  58. $capabilities |= self::GIS;
  59. }
  60. return $capabilities;
  61. }
  62. /**
  63. * Seeds the database for this connection
  64. *
  65. * @return void
  66. */
  67. public function seedDatabase($db, $capabilities)
  68. {
  69. $fixture = __DIR__.'/data/blog_mysql.sql';
  70. $i=0;
  71. if (mysqli_multi_query($db, file_get_contents($fixture))) {
  72. do { $i++; mysqli_next_result($db); } while (mysqli_more_results($db));
  73. }
  74. if (mysqli_errno($db)) {
  75. die("Loading '$fixture' failed on statemement #$i with error:\n".mysqli_error($db)."\n");
  76. }
  77. }
  78. }