Jump to content

How do I get php to read a table from MS SQL


rich11

Recommended Posts

Hello...

 

I am new to php and not sure how to get php to work with MS SQL.

 

Do i need to set up a DSN???  And then use this code to contact the database??

 

$host="localhost";

$username="root";

$password="root";

$dbName="clients";

 

 

Thank you,

 

Rich

Link to comment
Share on other sites

  • 4 weeks later...

Rich,

 

i am new too, but have this working. You are missing the bits of code that do the $conn=odbc_connect and a few others which I am sure you know just didnt put in the forum (I presume that you have been to www.php.net and searched on this command, does show good examples etc).

The bit that isnt shown is the DSN, which you do need.

 

So install SQL, any machine. Best run mixed mode

Create Datbase, and or table

Go to machine where php, control panel, admin, odbc datasource

create a SYSTEM dsn.

give a name (database name)

ensure you say where SQL server is (if local give local NAME) (ping to check)

Change the database (tick box) as required

Enter sa and sa password

TEST (should say ok) then save

try changing localhostname to the IP address of the server as well to make sure that isnt a problem.

 

Hope this shorthand makes sense

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I used mssql_connect and other function like my the mysql_functions.

 

For example:

 

$connection = mssql_connect("Server","user") // include your password if needed

 

mssql_select_db("table_name", $connection)

 

$result = mssql_query("select * .......", $connection)

 

while ($row = mssql_fetch_array($result))

{

      // for example

      echo $row["field_name"]

 

}

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.