Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:

i am using windows server 2008, iis7, sqlserver 2005, php 5.2.6

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 229 [Microsoft][SQL Native Client][SQL Server]The SELECT permission was denied on the object 'payments', database 'ow1222', schema 'dbo'. (SQLExecute[229] at ext\pdo_odbc\odbc_stmt.c:133)' in C:\inetpub\wwwroot\missing4.php:25 Stack trace: #0 C:\inetpub\wwwroot\missing4.php(25): PDOStatement->execute() #1 C:\inetpub\wwwroot\missing4.php(39): dbfetcharray('??select * from...') #2 {main} thrown in C:\inetpub\wwwroot\missing4.php on line 25

$db = new PDO("odbc:Driver={SQL Native Client};Server=$ip;Database=$database;dbname=$database",$user,$pass);

function dbfetcharray($sql) {
  global $db;
  //try {
    $rs = $db->prepare($sql);
    return $rs->fetchAll();
  //catch(PDOException $e) {
  echo '<br>begin';
select * from payments
foreach($payments as $p){
    echo $p['orderid'];
}//end foreach
echo '<br>end';

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron TomoskyDirector of Solutions ConsultingCommented:
It looks like your select statement has some ?? In it. Define the query outside of the dbfetcharray function, echo it, and use that variable in the function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
is obdc working on windows server

this code worked on another windows server
rgb192Author Commented:
i changed the code to echo the error.

I have a similar question

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.