• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Retrieve data from sqlServer in php

lili_ll23

New Member
Hi
I have sQLServer database and i want to retrieve data from sql-server in utf-8
format using php5. but aren't showed correctly.
please help me.
 
HTML:
yes. I use this code : 
<?php

    $link = mssql_connect('ict2', 'sa', '142');
    mssql_select_db('library', $link);
    $utf8 = 'پپپمناژژژژژژزززگگگگگگچچچچچچچچچچچچ';  // some Greek text for example
    $ucs2 = iconv('UTF-8', 'UCS-2LE', $utf8);
	$arr = unpack('H*hex', $ucs2);
    $hex = "0x{$arr['hex']}";
    mssql_query("insert into book (price,name) values (1200,{$hex})",$link);
	//mssql_query("SET sa utf-8");
//mssql_query("SET CHARACTER SET utf-8");

$query = "SELECT name FROM book"; 
    $result = mssql_query($query, $link);
    while (($row = mssql_fetch_array($result, MSSQL_BOTH)))
    {
        // we get data in UCS-2
        // I use UTF-8 in my project, so I encode it back
		//echo "&&&&";
      echo $row['name'];
    }
	//convert_uudecode($hex);
 //convert(varbinary(200),$hex);
    mssql_free_result($result);
    mssql_close($link);

?>
 
You do pretty much the same for connecting to a MySQL database, you'd use the mssql_connect and mssql_select_db functions first of all to connect then you'd do a MSSQL query with this function. PHP really has gone its way to support MSSQL databases, pretty simple stuff :). To retrieve data, you'd use the mssql_fetch_array() function, btw :)

MSSQL Functions
 
Back
Top