KevBrad Posted February 11, 2009 Share Posted February 11, 2009 Hi, I predominantly use PHP with MySQL but have recently been needed to interact with MS SQL database for a client. I can connect to the server and run sp_databases and sp_tables to determin the higher structure however if I try to execute a simple SELECT command I run into errors. For example; $link = mssql_connect("server_name","username","password"); $sql = "SELECT * FROM database_name.table_name;"; $res = mssql_query($sql, $link); for($i=0; $i<mssql_num_fields($res, $link); $i++) { $field = mssql_fetch_field($res, $i); echo $field->name." | ".$field->type."<br />"; } I get 3 error codes, the first being the most important which is "Invalid Object Name:...". I know this is an SQL error but I cannot seem to find the correct code to output anything. My goal is to first obtain the structure of the database, tables, columns and then pursue retrieving individual records. Where am I going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/144747-solved-mssql-query-errors/ Share on other sites More sharing options...
corbin Posted February 11, 2009 Share Posted February 11, 2009 You have to do database.user.table. For example: database_name.dbo.table_name. (Assuming the connection was using the database owner as the user.) Quote Link to comment https://forums.phpfreaks.com/topic/144747-solved-mssql-query-errors/#findComment-760008 Share on other sites More sharing options...
KevBrad Posted February 12, 2009 Author Share Posted February 12, 2009 This has now been solved. My syntax was incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/144747-solved-mssql-query-errors/#findComment-760346 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.