The SELECT permission was denied on the object 'payments', database 'database'

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

SQLSTATE[42000]: Syntax error or access violation: 229 [Microsoft][SQL Native Client][SQL Server]The SELECT permission was denied on the object 'payments', database 'database', schema 'dbo'. (SQLExecute[229] at ext\pdo_odbc\odbc_stmt.c:133)04/10 02:57:19PM | dbfetcharray |
select * from payments

$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) {
function recordSQLError($function,$sql,$error) {
    $fp = fopen($logfile, 'a');
  fwrite($fp, $error);
    fwrite($fp, date("m/d h:i:sA"));
    fwrite($fp, " | $function | ");
    //fwrite($fp, " | SQL: ");
    fwrite($fp, $sql);
    //fwrite($fp, " | Error: ");
  //fwrite($fp, " ||| ");
    fwrite($fp, "\r\n");
  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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

It means the user in the connection string

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

does not have access to the table 'payments' in the database.

Try giving the user the role db_datareader to the database within SQL Server Management Studio

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:
this has the role 'db_owner'.. is that good enough
Anthony PerkinsCommented:
This is a duplicate question (of the question below).  Please request that this thread be deleted.
rgb192Author Commented:
that question I was told to display the error of which i unccommented lines and added a function

I opened a similar question.

I think the two questions are very similar.

I still dont understand the answer to this question (now that the error is displayed)
rgb192Author Commented:
sorry for the confusion
I found  db_datareader on the second screen (in sql server) and added it
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.