1

When I run php script to export MSSQL server table data I got this error message:

Warning: mssql_query() [function.mssql-query]: message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Newitemtest\csv3.php on line 22

Can anyone point me in correct way? Thank you so much in advance.

Below is my php script

<?php
    $myServer = "****";
    $myUser = "**";
    $myPass = "****";
    $myDB = "***";

    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
            or die("Couldn't connect to SQL Server on $myServer"); 

        $selected = mssql_select_db($myDB, $dbhandle)
            or die("Couldn't open database $myDB"); 

        $query = "SELECT * ";
        $query .= "FROM Item ";
        $result = mssql_query($query, $dbhandle);

    while ($l = mssql_fetch_array($result, MSSQL_ASSOC)) {
    foreach($l AS $key => $value){
        $pos = strpos($value, '"');
            if ($pos !== false) {
                $value = str_replace('"', '\"', $value);
            }
            $out .= '"'.$value.'",';
    }
    $out .= "\n";
    }
    mssql_free_result($result);
    mssql_close($dbhandle);

    header("Content-type: text/x-csv");
    header("Content-Disposition: attachment; filename=export.csv");
    echo $out;
?>
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.