[....]On Tue, 14 Jul 2009 18:13:56 -0500
Vijay Sankar wrote:> I am trying to access a database hosted on a Microsoft SQL Server 2005
Here is a trivialized interface to mssql using freetds and php.
It supports reads and writes.
Dhu
<?php
/*
Copyright (C) <2005> (Bzerkley terms)
Duncan Patton a Campbell can be contacted at campbell@neotext.ca, or campbell@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();
?>
| Jeff Garzik | Re: [RFC] Heads up on sys_fallocate() |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Greg Kroah-Hartman | [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO |
| Anton Salikhmetov | [PATCH -v8 3/4] Enable the MS_ASYNC functionality in sys_msync() |
git: | |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| David Miller | Re: xfrm_state locking regression... |
| Jarek Poplawski | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| David Miller | Re: [PATCH 3/3] Convert the UDP hash lock to RCU |
