Jump to content

[SOLVED] MSSQL Query Errors


KevBrad

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/144747-solved-mssql-query-errors/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.