Advertisement
Guest User

Untitled

a guest
Oct 10th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. $myServer = "192.168.0.55";
  3. $myUser = "sa";
  4. $myPass = "password";
  5. $myDB = "mydb";
  6.  
  7. //create an instance of the ADO connection object
  8. $conn = new COM ("ADODB.Connection")
  9. or die("Cannot start ADO");
  10.  
  11. //define connection string, specify database driver
  12. $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
  13. $conn->open($connStr); //Open the connection to the database
  14.  
  15. //declare the SQL statement that will query the database
  16. $query = "SELECT * FROM mytable";
  17.  
  18. //execute the SQL statement and return records
  19. $rs = $conn->execute($query);
  20.  
  21. $num_columns = $rs->Fields->Count();
  22. echo $num_columns . "<br>";
  23.  
  24. for ($i=0; $i < $num_columns; $i++) {
  25. $fld[$i] = $rs->Fields($i);
  26. }
  27.  
  28. echo "<table>";
  29. while (!$rs->EOF) //carry on looping through while there are records
  30. {
  31. echo "<tr>";
  32. for ($i=0; $i < $num_columns; $i++) {
  33. echo "<td>" . $fld[$i]->value . "</td>";
  34. }
  35. echo "</tr>";
  36. $rs->MoveNext(); //move on to the next record
  37. }
  38.  
  39.  
  40. echo "</table>";
  41.  
  42. //close the connection and recordset objects freeing up resources
  43. $rs->Close();
  44. $conn->Close();
  45.  
  46. $rs = null;
  47. $conn = null;
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement