First make a odbc DSN to the MSSQL database.
Here is a code sample of how I connect to my MSSQL server via PHP.
This is inside my class_db.php

class Db
        var $datasource;                // Data source į server
        var $username;
        var $password;
        var $connect;           // Connect strengurinn
    function Db() //Smišur klasa -> default constructor
                $this->datasource = "vcdmssql";  // the name of the DSN
                $this->username = "misteruser"; // your username
                $this->password = "somepass"; // and password
                $this->connect = odbc_connect($this->datasource,
$this->username, $this->password);

        function sql($sql_string)
                return odbc_exec($this->connect, $sql_string);
        function fjoldi($recordset)
                return odbc_num_rows($recordset);


Then make a new instance of the class ..
$db = new db;
$query = "SELECT id,name from movies";
$get = $db->sql($query);  // make the query
while (odbc_fetch_row($get))  // walk through all results
        $id = odbc_result($get,1);
        $name = odbc_result($get,2);
        echo "$name" has id $id;

Hope this helps,

-----Original Message-----
From: Joseph Szobody [mailto:[EMAIL PROTECTED]] 
Sent: 20. september 2002 22:44
Subject: [PHP-DB] PHP - MSSQL


I have a situation where I need a Visual Basic program, running on a
win2k server to store some data. I later need a PHP script to come
along, retrieve and parse that data. I have a MS SQL server running on
the win2k server along with the VP program. I then have a RedHat/Apache
box that the PHP script is running on, which also has MySQL.

My first thought was to have the VP app store the data in a MS SQL table
(since this is the easiest for the VP programmer), and then I (the PHP
programmer) would have to figure out how to connect the the MS SQL table
with PHP. I know this is possible, but I've also heard it can be messy
(recompiling PHP..... installing odbc drivers which sometimes give
errors.... etc).

The other option, is to do it the other way around. Have the VB guy
write the data to a MySQL table, which then would be a piece of cake for
me to retrieve with PHP. What I don't know, is how easy it is for VB to
talk to MySQL.

Anyone have experience with either way? I know PHP fairly well, but I'm
not too sure about the installation/compiling/etc process to get odbc

Any tips or advice would be appreciated. Thanks!


PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to