impactfactor Posted January 7, 2011 Share Posted January 7, 2011 The following is the error I am receiving: Warning: mssql_query(): message: Incorrect syntax near the keyword 'User'. (severity 15) in /var/www/try.php on line 25 I understand User is a protected keyword in SQL Server but how can I get past this? Do I have to surround the word user in specific characters? My code is below: <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $con = mssql_connect('172.21.30.19', 'sa', 'nsn4hill'); if (!$con) { die('Could not connect: ' . mssql_error()); } mssql_select_db("Intranet", $con); $sql="SELECT CAST UserID AS TEXT FROM User"; $result = mssql_query($sql); echo "<table border='1'> <tr> <COL width='100'> <th bgcolor='black' style ='color:white'>Patch ID</th> </tr>"; while($row = mssql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['UserID'] . "</td>"; echo "</tr>"; } echo "</table>"; mssql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/223704-php-mssql-incorrect-syntax-near-the-keyword-user-error/ Share on other sites More sharing options...
Brian Swan Posted January 10, 2011 Share Posted January 10, 2011 Have you tried using square brackets around User to indicate it is not the keyword user? $sql="SELECT CAST UserID AS TEXT FROM [user]"; This works for me. Hope that helps. -Brian Quote Link to comment https://forums.phpfreaks.com/topic/223704-php-mssql-incorrect-syntax-near-the-keyword-user-error/#findComment-1157458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.