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
<?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());
  }
}  
  
  
  
function recordSQLError($function,$sql,$error) {
$logfile="errorlog.txt";
    $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");
    fclose($fp);
}  
  
  
  
  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.

cyberkiwiCommented:
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
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:
this has the role 'db_owner'.. is that good enough
0
Anthony PerkinsCommented:
This is a duplicate question (of the question below).  Please request that this thread be deleted.

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_26946277.html
0
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)
0
rgb192Author Commented:
sorry for the confusion
I found  db_datareader on the second screen (in sql server) and added it
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.