Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I using ODBC to connect sql server 2008 like
$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);
But i get text not correct like
b?�o c?�o việc sử dụng
i try to using odbc_exec($conn, "SET names utf8");
but get error
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
How set utf-8 using odbc_connect thanks
–
–
–
odbc_exec doesn't accept 'SET NAMES utf8' as second parameter. the second parameter must be the query.
to set utf8 for variables only use utf8_decode or iconv
$col1=utf8_decode(odbc_result($rs, "name"));
$col1=odbc_result($rs, "name");
iconv("UTF-8", "CP1252", $col1);
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
this is not an error, is a WARNING. but check odbc_exec manual to ensure all.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.