Page 1 of 1

Returning garbage from SQL database

Posted: Fri May 14, 2010 9:38 am
by mauritzg
Hi forum
I hope someone can help me. As of this morning, I get weird results from my db queries. I’m using php 5.2.9 running on IIS web server, connecting to a server with MS SQL 2008 database via the php odbc functions.

On the test web host the results from the database comes back fine put on the “production” web host the db query return garbage. Could this be a SQL Server Driver problem?

What should come back as “IT Cape Town (Support)”comes back as “'} #�� !��� ���8'} _u”

It has work 100% for a very long time and now, almost overnight it’s giving this problem.

Has anyone seen this type of problem before?

This connection code looks like this:
function OpenDb()
{
global $DB_SERVER,$DB_DBNAME,$DB_USER,$DB_PWR;
$secretPass = 'kljhflk73#OO#*U$O(*YO';
$pwr=Encode(hex2bin($DB_PWR),$secretPass);
$connection_string = 'DRIVER={SQL Server};SERVER='.$DB_SERVER.';DATABASE='.$DB_DBNAME;
$connection = odbc_connect( $connection_string, $DB_USER, $pwr);
if (odbc_error())
{
echo odbc_errormsg($connection);
}
return $connection;
}
And the Execute code
//Execute SQL Query
function DbExecute($SQLQuery,$DbConn)
{
$result=odbc_exec($DbConn,$SQLQuery) ;
if (odbc_error())
{
echo odbc_errormsg($conn);
}
return $result;

}

Re: Returning garbage from SQL database

Posted: Fri May 14, 2010 1:53 pm
by JakeJ
Could something in the code that's putting the data in to the database be different?

addslashes() and stripslashes() should be used for data coming in and out of your database.