test_connect.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Init: config connection to MSSQL
  4. */
  5. ini_set('display_errors',1);
  6. ini_set('mssql.datetimeconvert',0);
  7. $eol = "<br />";
  8. if (PHP_SAPI == 'cli') {
  9. $eol = "\n";
  10. }
  11. /**
  12. * Load connect info
  13. */
  14. //require 'config.dist.php';
  15. $db_host = substr(htmlentities(empty($_POST['host'])?'':$_POST['host']),0,25);
  16. $db_user = substr(htmlentities(empty($_POST['user'])?'':$_POST['user']),0,25);
  17. $db_pass = substr(htmlentities(empty($_POST['pass'])?'':$_POST['pass']),0,25);
  18. $db_name = substr(htmlentities(empty($_POST['name'])?'':$_POST['name']),0,25);
  19. echo '<p><form action="" method="POST">';
  20. echo '<table>';
  21. echo '<tr><td>Host:</td><td><input type="text" name="host">'.(empty($db_host)?'':$db_host).'</input></td></tr>';
  22. echo '<tr><td>User:</td><td><input type="text" name="user">'.(empty($db_user)?'':$db_user).'</input></td></tr>';
  23. echo '<tr><td>Pass:</td><td><input type="text" name="pass">'.(empty($db_pass)?'':$db_pass).'</input></td></tr>';
  24. echo '<tr><td>Base:</td><td><input type="text" name="name">'.(empty($db_name)?'':$db_name).'</input></td></tr>';
  25. echo '<tr><td colspan="2"><input type="submit" name="ok" value="Test"></td></tr>';
  26. echo '</table>';
  27. echo '</form></p>';
  28. /**
  29. * Try connecting
  30. */
  31. $conn = @mssql_connect($db_host,$db_user,$db_pass,TRUE);
  32. if ($conn == FALSE) {
  33. printf("Could not connect. MSSQL error: %s$eol",mssql_get_last_message());
  34. die();
  35. }
  36. echo "Connected$eol";
  37. /**
  38. * Try querying
  39. */
  40. mssql_select_db($db_name,$conn);
  41. $sql = 'SELECT MAX(idt) FROM Transaccion';
  42. $res = @mssql_query($sql,$conn);
  43. if ($res === false) {
  44. echo "Error with query ".$sql.". MSSQL error: ".mssql_get_last_message().$eol;
  45. die();
  46. }
  47. $row = @mssql_fetch_array($res);
  48. print_r($row);
  49. echo $eol;
  50. $sql = 'SELECT cast(uidIdAlumno as varchar(50)) FROM Alumno WHERE intIdAlumno = 62165';
  51. $res = @mssql_query($sql,$conn);
  52. if ($res === false) {
  53. echo "Error with query ".$sql.". MSSQL error: ".mssql_get_last_message().$eol;
  54. die();
  55. }
  56. $row = @mssql_fetch_array($res);
  57. print_r($row);
  58. echo $eol;