Retrieving Results of a Query to MSSQL


 $result = mssql_query(); mssql_fetch_assoc($result); 


Finally, there is, of course, also a way to retrieve all data in the resultset. A while loop comes into play, using one of these functions:

  • mssql_fetch_assoc() returns the current row in the resultset as an associative array

  • mssql_fetch_object() returns the current row in the resultset as an object

  • mssql_fetch_row() returns the current row in the resultset as a numeric array

Retrieving Data from MSSQL/MSDE (mssql_fetch.php; excerpt)
 <table> <tr><th>#</th><th>Quote</th><th>Author</th><th>Year<   /th></tr> <?php   if ($db = @mssql_connect('localhost', 'user',     'password')) {     mssql_select_db('phrasebook', $db);     $result = mssql_query('SELECT * FROM quotes',       $db);     while ($row = mssql_fetch_assoc($result)) {       printf(         '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></    tr>',         htmlspecialchars($row['id']),         htmlspecialchars($row['quote']),         htmlspecialchars($row['author']),         htmlspecialchars($row['year'])       );     }     mssql_close($db);   } else {     echo '<tr><td colspan="4">Connection       failed.</td></tr>';   } ?> </table> 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net