Returning garbage from SQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mauritzg
Forum Newbie
Posts: 1
Joined: Fri May 14, 2010 9:04 am

Returning garbage from SQL database

Post 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;

}
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Returning garbage from SQL database

Post 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.
Post Reply