我使用 ODBC 连接 sql server 2008 之类的
$virtual_dsn = 'DRIVER={SQL Server};SERVER=MyServerName;DATABASE=myDatabase';
$conn = odbc_connect($virtual_dsn,'sa','mypass') or die('ODBC Error:: '.odbc_error().' :: '.odbc_errormsg().' :: '.$virtual_dsn);
if (!$conn){
if (phpversion() < '4.0'){
exit("Connection Failed: . $php_errormsg" );
}
else{
exit("Connection Failed:" . odbc_errormsg() );
}
}
// This query generates a result set with one record in it.
$sql="SELECT TOP 10 * FROM Mytable";
# Execute the statement.
$rs=odbc_exec($conn,$sql);
// Fetch and display the result set value.
if (!$rs){
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
$col1=odbc_result($rs, "name");
echo "$col1 <br>";
}
// Disconnect the database from the database handle.
odbc_close($conn);
但我得到的文字不正确
b?�o c?�o việc sử dụng
我尝试使用odbc_exec($conn, "SET names utf8");
但得到错误
Warning: odbc_exec(): SQL error: [Microsoft][SQL Server Native Client 10.0][SQL Server]'names' is not a recognized SET option., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\sql\index.php on line 32
如何使用 odbc_connect 设置 utf-8 谢谢