Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. /*
  3. PHP MSSQL Example
  4.  
  5. Replace data_source_name with the name of your data source.
  6. Replace database_username and database_password
  7. with the SQL Server database username and password.
  8. */
  9. $data_source='SQLSERVER';
  10. $user='sa';
  11. $password='12345678';
  12.  
  13. // Connect to the data source and get a handle for that connection.
  14. $conn=odbc_connect($data_source,$user,$password);
  15. if (!$conn){
  16.     if (phpversion() < '4.0'){
  17.         exit("Connection Failed: . $php_errormsg" );
  18.     }
  19.     else{
  20.         exit("Connection Failed:" . odbc_errormsg() );
  21.     }
  22. }
  23.  
  24. // This query generates a result set with one record in it.
  25. $sql="use hw7; select distinct name, phone from Sales_Rep sr, Car c where sr.name = c.seller and c.color = 'color1';";
  26.  
  27. //select distinct name, phone from Sales_Rep sr, Car c where sr.name = c.seller and c.color = 'color1'
  28.  
  29. # Execute the statement.
  30. $rs=odbc_exec($conn,$sql);
  31.  
  32. // Fetch and display the result set value.
  33. if (!$rs){
  34.     exit("Error in SQL");
  35. }
  36. while (odbc_fetch_row($rs)){
  37.     $col1=odbc_result($rs, "name");
  38.     $col2=odbc_result($rs, "phone");
  39.     echo "$col1 ";
  40.     echo "$col2";
  41.     echo "<br>";
  42. }
  43.  
  44. // Disconnect the database from the database handle.
  45. odbc_close($conn);
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement