PHP MSSQL Query a problem (ask)

Source: Internet
Author: User
PHP MS SQL Select

Get all values for the entire column, and convert to a 2-D array.
function GetAll ($sql) {
$query =mssql_query ($sql);
if ($query) {
$temp =array ();
while ($res =mssql_fetch_assoc ($query)) {
$temp []= $res;
}
return $temp;
}
else{
return false;
}
}
$result = "Select ZDMC from QX WHERE jsid=9 and tcmc= ' $DITCBO ' and kj=1";
$arr =getall ($result);
Convert a two-dimensional array to a string separated by a single and comma
for ($i =0; $i
$array [] = $arr [$i] ["ZDMC"];
}
$r = "'". Implode ("', '", $array). "'";
Use this string to query the table
$result 2 = Mssql_query ("Select $r from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)
The results are displayed as


Garbled is because this is read is Mmsql GBK code, used when I will be converted, but now read in the content is not correct
New handwriting, begging for help, bro.


Reply to discussion (solution)

$r = ' ['. Implode ("],[", $array). '] ';
Since the $r is a list of fields, wouldn't it be a string to enclose it in single quotation marks?
Look, your field names are mostly in Chinese. This requires the field name to be surrounded by [] and you can see it in SQL Server Manager

Do you mean to enclose the field names in brackets and separate them with commas?
I copied the error you gave me.

You give the wrong message when you make an error

function GetAll ($sql) {
$query =mssql_query ($sql);
if ($query) {
$temp =array ();
while ($res =mssql_fetch_assoc ($query)) {
$temp []= $res;
}
return $temp;
}
else{
return false;
}
}
$result = "Select ZDMC from QX WHERE jsid=9 and tcmc= ' $DITCBO ' and kj=1";
$arr =getall ($result);
for ($i =0; $i
$array [] = $arr [$i] ["ZDMC"];
}
$r = ' ['. Implode ("],[", $array). '] ';
$r = "'". Implode (",", $array). "'";
$result 2 = Mssql_query ("Select from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)

I'm sorry, I'll help you see.

Who can see your mess of stickers?

$r = ' ['. Implode ("],[", $array). '] ';
echo Convert2utf8 ($R);
Echo GetType ($R);
Show "UTF8" as Chinese results


Then, with the original GBK code, the table is tested to read the normal, do not know where the problem is AH!
$r = ' ['. Implode ("],[", $array). '] ';
$result 2 = Mssql_query ("Select $r from $SJB WHERE id= ' $bh '");
$row = Mssql_fetch_array ($result 2);
Print_r ($row)



Where did the string in the first sheet come from?
It's better to deal with Chinese mssq or GBK code.

echo a bit GetType ($R);
If this is different, then you have to think of another way.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.