On Tue, 14 Jul 2009 18:13:56 -0500
Vijay Sankar <vsan...@foretell.ca> wrote:

> I am trying to access a database hosted on a Microsoft SQL Server 2005 
> using FreeTDS and iodbc from OpenBSD 4.5 -stable (also tried OpenBSD 
> -current as of today). Unfortunately none of the documents I have read 
> so far or the various trials/tests have helped. I can use tsql and 
> access the SQL Server but I am not able to use iodbcadm-gtk to add a DSN 
> etc.
> 
> The standard package as well as the msdblib flavor did not work for me 
> and as a result I made a few changes to the Makefile
> 
> Looks like I made some small progress however, I get the error
> 
> HYC00 [FreeTDS][SQL Server]Driver not capable
> 08001: [FreeTDS][SQL Server]Unable to connect to data source
> 
[....]
> 
> I hope the list can give me any advice or pointers on what is the best 
> way to access data from a SQL Server 2005 database from OpenBSD
> 
> Thanks very much,
> 
> Vijay
> 
> -- 
> Vijay Sankar, M.Eng., P.Eng.
> ForeTell Technologies Limited
> 59 Flamingo Avenue, Winnipeg, MB, Canada R3J 0X6
> Phone: (204) 885-9535, E-Mail: vsan...@foretell.ca
> 
> 

Here is a trivialized interface to mssql using freetds and php.
It supports reads and writes.

Dhu

<?php
/*
Copyright (C) <2005>  <Duncan Patton a Campbell aka Duncan Duibh> (Bzerkley 
terms)

Duncan Patton a Campbell can be contacted at campb...@neotext.ca, or 
campb...@indx.ca.
sqNdhu.php -- general purpose access to SQL databases .. here implemented for 
commandline operations
php -f sqNdhu.php
line one on stdin == MSSQL/MSHOST:1433/Uname/Upass/Dbname/
line one on stdin == MYSQL/MYHOST:3306/Uname/Upass/Dbname/
line two thru n-1 == select/insert/replace...
line n == \n

uses http://www.freetds.org/ libraries 

*/

$stdinline = trim(fgets(STDIN));

list($stype,$hnp,$dbu,$dbp,$dbn) = split("/", $stdinline) ;

switch ($stype)
{

        case    "MSSQL":
        {
                $db =   mssql_connect($hnp,$dbu,$dbp);
                if(!$db)
                {
$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "Could not connect"); 
fwrite($handle, "\n\n"); fclose($handle);
                        exit("Could not connect");
                }
                if(!mssql_select_db($dbn,$db))
                {
$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "Could not select 
database"); fwrite($handle, "\n\n"); fclose($handle);
                        exit("Could not select database");
                }
/* Performing SQL query */
        while($squery= trim(fgets(STDIN)))
                {
//$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "MySqery:".$squery); 
fwrite($handle, "\n\n"); fclose($handle);
                $result = mssql_query($squery) or die("Query failed : " . 
$squery);
                if(is_resource($result))
                        {
                        $num_results = mssql_num_rows($result);
                        echo "\n" . $num_results;
                        if($num_results == 0) echo "\n";
                        for ($i=0; $i <$num_results; $i++)
                                {
                                while($myrow = mssql_fetch_row($result))
                                        {
                                        $colcnt = count($myrow);
                                        echo "\n" . $colcnt;
                                        for($x=0; $x < $colcnt; $x++)
                                                {
                                                echo sprintf("\n%d 
",strlen($myrow[$x])) . $myrow[$x];
                                                }
                                        }
                                }
                        mssql_free_result($result);
                        }
                else
                        {
                        echo "\n1\n1\n1 !";
                        }
                }
        mssql_close($db);
        }
        break;

        case    "MYSQL":
        {
                $db =   mysql_connect($hnp,$dbu,$dbp);
                if(!$db)
                {
$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "Could not connect"); 
fwrite($handle, "\n\n"); fclose($handle);
                        exit("Could not connect");
                }
                if(!mysql_select_db($dbn,$db))
                {
$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "Could not select 
database"); fwrite($handle, "\n\n"); fclose($handle);
                        exit("Could not select database");
                }
/* Performing SQL query */
        while($squery= trim(fgets(STDIN)))
                {
//$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "MySqery:".$squery); 
fwrite($handle, "\n\n"); fclose($handle);
                $result = mysql_query($squery) or die("Query failed : " . 
$squery);
                if(is_resource($result))
                        {
                        $num_results = mysql_num_rows($result);
                        echo "\n" . $num_results;
                        if($num_results == 0) echo "\n";
                        for ($i=0; $i <$num_results; $i++)
                                {
                                while($myrow = mysql_fetch_row($result))
                                        {
                                        $colcnt = count($myrow);
                                        echo "\n" . $colcnt;
                                        for($x=0; $x < $colcnt; $x++)
                                                {
                                                echo sprintf("\n%d 
",strlen($myrow[$x])) . $myrow[$x];
//$handle=fopen('/tmp/perror.err', 'a');fwrite($handle, "."); fwrite($handle, 
"-"); fclose($handle);
                                                }
                                        }
                                }
                        mysql_free_result($result);
                        }
                else
                        {
                        echo "\n1\n1\n1 !";
                        }
                }
        mysql_close($db);
        }
        break;
}       //end switch

fflush(STDOUT);
exit();

?>

Reply via email to