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

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

begin
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

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

  
  
  
  
function dbfetcharray($sql) {
  global $db;
  //try {
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $rs = $db->prepare($sql);
    $rs->execute();
    //recordSQLError("a1",$sql,"");
    return $rs->fetchAll();
  //}
  //catch(PDOException $e) {
    //recordSQLError("dbfetcharray",$sql,$e->getMessage());
  //}
}  
  
  
  echo '<br>begin';
$sql="
select * from payments
";
$payments=dbfetcharray($sql);
foreach($payments as $p){
    echo $p['orderid'];
}//end foreach
echo '<br>end';
?>

Open in new window

LVL 1
rgb192Asked:
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 TomoskySD-WAN SimplifiedCommented:
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.
0

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
0
rgb192Author Commented:
i changed the code to echo the error.

I have a similar question

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_26946297.html
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.