我在PHP应用程序中有一条错误消息,该消息不断指向更新失败,但报告未授予我的Select命令。
SQLSTATE [42000]:语法错误或访问冲突:1142 SELECT 表'actionitems'的用户'vahejaba'@'localhost'命令被拒绝
这是触发vahejaba @ loalhost上的选择授予无效错误的更新方法。
为什么我会在更新时遇到选择错误,为什么我的用户名不正确(由于某种原因我认为是导致错误的原因,所以这是不正确的)?
请帮助。
database.php
class Database
{
private static $instance;
private $dbh;
private static $dbengine = 'mysql';
private $dbname;
private static $dbhost = 'localhost';
function __construct()
{
$this->dbname = "vahejaba_projectaim"; //str_replace('.projectaim.tools', '', $_SERVER['HTTP_HOST']); //Config::$dbname;
$dbhost = Database::$dbhost;
$dbengine = Database::$dbengine;
$username = Config::$username;
$password = Config::$password;
try
{
$this->dbh = new PDO("$dbengine:host=$dbhost;dbname=$this->dbname", $username, $password);
}
catch (PDOException $e)
{
die("Error in establishing connection to database!");
}
}
public function update($table, $colsVals=null, $whereVals=null)
{
$table = $this->getTable($table);
$columns = "";
$valuelist = array();
$values = "";
$params = array();
$where = $this->where($whereVals);
$wherestr = $where['wherestring'];
$whereParams = $where['params'];
$set = $this->set($colsVals);
$setVals = $set['set'];
$setParams = $set['params'];
$setValsString = $set['setvals'];
$vals = $set['vals'];
$params = array_merge($whereParams, $setParams);
if ($table !== FALSE)
{
try
{
$dbname = $this->dbname;
$sql = $this->dbh->prepare("UPDATE $table SET $setValsString WHERE $wherestr");
$sql->execute($setParams);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
die('Update failed: '. $e->getMessage());
}
}
}
}
config.php
class Config
{
static $username = 'vahejaba_user';
}
manageActionItems.php
class ManageActionItems
{
private $db;
private $dbh;
private $userManager;
private $cols;
private $rowCount;
private $vals;
private $actionItemGrid;
private $requiredCols;
private $projectId;
private $table;
private $tool;
function __construct($excludeCols = array(), $requiredCols = array(), $projectId)
{
$this->db = Database::getInstance();
$this->userManager = new UserManager();
$this->dbh = $this->db->getHandle();
$this->table = 'ActionItems';
$this->tool = 'actionitem';
$this->requiredCols = $requiredCols;
$this->projectId = $projectId;
$this->actionItemGrid = new Grid($this->table, $excludeCols);
$this->cols = $this->actionItemGrid->getCols();
$this->rowCount = $this->actionItemGrid->getRowCount();
}
public function edit($id)
{
if (isset($_SESSION['errmsg']))
unset($_SESSION['errmsg']);
$ymdDueDate = "";
$ymdAssigned = "";
$ymdECD = "";
$ymdClosedDate = "";
$ymdCompletionDate = "";
$colsVals = array();
if (isset($_POST['editAssignedDate']) && $_POST['editAssignedDate'] != "" && $this->checkDate($_POST['editAssignedDate']))
{
$mdy = preg_split('/\//', $_POST['editAssignedDate']);
$ymdAssigned = "$mdy[2]-$mdy[0]-$mdy[1]";
}
else if (isset($_SESSION['AssignedDate']) && $_SESSION['AssignedDate'] != "")
{
$mdy = preg_split('/\//', $_SESSION['AssignedDate']);
$ymdAssigned = "$mdy[2]-$mdy[0]-$mdy[1]";
}
if (isset($_POST['editDueDate']) && $_POST['editDueDate'] != "" && $this->checkDate($_POST['editDueDate']))
{
$mdy = preg_split('/\//', $_POST['editDueDate']);
$ymdDueDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
else if (isset($_SESSION['DueDate']) && $_SESSION['DueDate'] != "")
{
$mdy = preg_split('/\//', $_SESSION['DueDate']);
$ymdDueDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
if (isset($_POST['editECD']) && $_POST['editECD'] != "" && $this->checkDate($_POST['editECD']))
{
$mdy = preg_split('/\//', $_POST['editECD']);
$ymdECD = "$mdy[2]-$mdy[0]-$mdy[1]";
}
else if (isset($_SESSION['ECD']) && $_SESSION['ECD'] != "")
{
$mdy = preg_split('/\//', $_SESSION['ECD']);
$ymdECD = "$mdy[2]-$mdy[0]-$mdy[1]";
}
if (isset($_POST['editClosedDate']) && $_POST['editClosedDate'] != "" && $this->checkDate($_POST['editClosedDate']))
{
$mdy = preg_split('/\//', $_POST['editClosedDate']);
$ymdClosedDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
else if (isset($_SESSION['ClosedDate']) && $_SESSION['ClosedDate'] != "")
{
$mdy = preg_split('/\//', $_SESSION['ClosedDate']);
$ymdClosedDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
if (isset($_POST['editCompletionDate']) && $_POST['editCompletionDate'] != "" && $this->checkDate($_POST['editCompletionDate']))
{
$mdy = preg_split('/\//', $_POST['editCompletionDate']);
$ymdCompletionDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
else if (isset($_SESSION['CompletionDate']) && $_SESSION['CompletionDate'] != "")
{
$mdy = preg_split('/\//', $_SESSION['CompletionDate']);
$ymdCompletionDate = "$mdy[2]-$mdy[0]-$mdy[1]";
}
$this->vals['AssignedDate'] = $ymdAssigned;
$this->vals['DueDate'] = $ymdDueDate;
$this->vals['ECD'] = $ymdECD;
$this->vals['CompletionDate'] = $ymdCompletionDate;
$this->vals['ClosedDate'] = $ymdClosedDate;
if (isset($_POST['editAssignedDate']))
$_SESSION['AssignedDate'] = $_POST['editAssignedDate'];
if (isset($_POST['editDueDate']))
$_SESSION['DueDate'] = $_POST['editDueDate'];
if (isset($_POST['editECD']))
$_SESSION['ECD'] = $_POST['editECD'];
if (isset($_POST['editCompletionDate']))
$_SESSION['CompletionDate'] = $_POST['editCompletionDate'];
if (isset($_POST['editClosedDate']))
$_SESSION['ClosedDate'] = $_POST['editClosedDate'];
$this->saveEditVals();
if($ymdAssigned != "" && $ymdDueDate != "" && $ymdAssigned > $ymdDueDate)
{
$_SESSION['errmsg'] = 'Due Date Must be Greater or Equal to Assigned Date';
return false;
}
else
{
unset($_SESSION['errmsg']);
}
foreach ($this->cols as $col)
{
if (array_key_exists($col, $_SESSION))
{
if($col != "ApproverID" && $col != "AltOwnerID" && $col != "OwnerID" && $col != "AssignorID" && $col != "AssignedDate" && $col != "DueDate" && $col != "ECD" && $col != "ClosedDate" && $col != "CompletionDate" && $col != "ID" && $col != "ActionItemID" && $col != "ProjectID")
$colsVals[$col] = $_SESSION[$col];
else if($col == 'AssignorID' && isset($_SESSION[$col]) && $_SESSION[$col] != 0)
$colsVals[$col] = intval($_SESSION[$col]);
else if($col == 'AltOwnerID' && isset($_SESSION[$col]) && $_SESSION[$col] != 0)
$colsVals[$col] = intval($_SESSION[$col]);
else if($col == 'OwnerID' && isset($_SESSION[$col]) && $_SESSION[$col] != 0)
$colsVals[$col] = intval($_SESSION[$col]);
else if($col == 'ApproverID' && isset($_SESSION[$col]) && $_SESSION[$col] != 0)
$colsVals[$col] = intval($_SESSION[$col]);
//else if ($col == 'AssignorID' || $col == 'AltOwnerID' || $col == 'ApproverID' || $col == 'OwnerID' && !isset($_SESSION[$col]))
// $colsVals[$col] = 'NULL';
}
}
// $manageLockedFields = new ManageLockedFields('actionitem');
$colsVals['AssignedDate'] = $ymdAssigned;
$colsVals['DueDate'] = $ymdDueDate;
$colsVals['ClosedDate'] = $ymdClosedDate;
$colsVals['CompletionDate'] = $ymdCompletionDate;
$colsVals['ECD'] = $ymdECD;
$where = array();
if ($id != null)
{
$where[] = array('Selector', '=', "'".substr($id, 0, 12)."'");
}
$this->db->update($this->table, $colsVals, $where);
return true;
}
答案 0 :(得分:0)
在我的数据库(phpmyadmin)中,我有一个触发器,该触发器错误地指向了错误的用户名和错误的数据库名称。联系没有解决方案的Web主机后,我调查了触发器,并发现了问题。修改参数消除了错误。