Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- PHP MSSQL Example
- Replace data_source_name with the name of your data source.
- Replace database_username and database_password
- with the SQL Server database username and password.
- */
- $data_source='SQLSERVER';
- $user='sa';
- $password='12345678';
- // Connect to the data source and get a handle for that connection.
- $conn=odbc_connect($data_source,$user,$password);
- if (!$conn){
- if (phpversion() < '4.0'){
- exit("Connection Failed: . $php_errormsg" );
- }
- else{
- exit("Connection Failed:" . odbc_errormsg() );
- }
- }
- // This query generates a result set with one record in it.
- $sql="use hw7; select distinct name, phone from Sales_Rep sr, Car c where sr.name = c.seller and c.color = 'color1';";
- //select distinct name, phone from Sales_Rep sr, Car c where sr.name = c.seller and c.color = 'color1'
- # Execute the statement.
- $rs=odbc_exec($conn,$sql);
- // Fetch and display the result set value.
- if (!$rs){
- exit("Error in SQL");
- }
- while (odbc_fetch_row($rs)){
- $col1=odbc_result($rs, "name");
- $col2=odbc_result($rs, "phone");
- echo "$col1 ";
- echo "$col2";
- echo "<br>";
- }
- // Disconnect the database from the database handle.
- odbc_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement