I'm putting together a PHP website for a class project, and we are using a MS SQL Server 2008 database to populate fields on the site. However, one of the fields is outputting garbage onto the page instead of what is actually stored in the database.
The field in question, called description
, is a varchar(MAX)
field; a stored procedure queries the database for a tuple and dumps the values from its table into text boxes on the page; the description
field is output to a textarea
control.
Here is the PHP that handles pulling the information from the database:
$res = odbc_exec($dbhandle, "exec dbo.usp_ProgramGet " . $_GET["program"]);
$id = $_GET["program"];
$name = odbc_result($res, "title");
$desc = odbc_result($res, "description");
The $name
variable works as expected (in the database, it is of type char(15)
). However, if (for example) the description
field contains "This is a test" then $desc
will result in "�$ime�����", which is what gets dumped into the textarea
control, instead of what's stored in the database.
I've searched all over and found no solutions to this problem yet, although it sounds like a bug in PHP itself although I'm not sure.
Update
I am using SQL Server queries to update the varchar values. I tried putting in a really long string and I got this:
�,ime�������stringDayToInt��É������à‰,���N={���������������������������������������������
"stringDayToInt" is the name of a PHP function I wrote that lives in a totally different file that got included into the page I'm trying out. Very bizarre.