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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.