PHP&;PDO PHP注意事项:未定义属性:数据库::$photo?
好的,这是我正在使用的代码PHP&;PDO PHP注意事项:未定义属性:数据库::$photo?,php,pdo,Php,Pdo,好的,这是我正在使用的代码 function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto) { try { $stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :descriptio
function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto)
{
try {
$stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)");
if(!$stmt){
$err = $this->pdo->errorInfo();
throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]);
}
$stmt->bindValue(':title', $this->title, PDO::PARAM_STR);
$stmt->bindValue(':description', $this->description, PDO::PARAM_STR);
$stmt->bindValue(':price', $this->price, PDO::PARAM_INT);
$stmt->bindValue(':qty', $this->qty, PDO::PARAM_INT);
$stmt->bindValue(':photo', $this->photo, PDO::PARAM_STR);
$stmt->execute();
}catch (PDOException $e) {
echo $e->getMessage();
}
}
$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg');
数据库类和数据库调用函数工作。另外,如果您发现了任何可以改进的地方,请在我尝试学习时指出。为什么
$this->photo
?你们班上真的有这个属性吗?或者你需要这样的东西
function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto)
{
try {
$stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)");
if(!$stmt){
$err = $this->pdo->errorInfo();
throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]);
}
$stmt->bindValue(':title', $aTitle, PDO::PARAM_STR);
$stmt->bindValue(':description', $aDescription, PDO::PARAM_STR);
$stmt->bindValue(':price', $aPrice, PDO::PARAM_INT);
$stmt->bindValue(':qty', $aQty, PDO::PARAM_INT);
$stmt->bindValue(':photo', $aPhoto, PDO::PARAM_STR);
$stmt->execute();
}catch (PDOException $e) {
echo $e->getMessage();
}
}
$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg');
为什么
$this->photo
?你们班上真的有这个属性吗?或者你需要这样的东西
function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto)
{
try {
$stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)");
if(!$stmt){
$err = $this->pdo->errorInfo();
throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]);
}
$stmt->bindValue(':title', $aTitle, PDO::PARAM_STR);
$stmt->bindValue(':description', $aDescription, PDO::PARAM_STR);
$stmt->bindValue(':price', $aPrice, PDO::PARAM_INT);
$stmt->bindValue(':qty', $aQty, PDO::PARAM_INT);
$stmt->bindValue(':photo', $aPhoto, PDO::PARAM_STR);
$stmt->execute();
}catch (PDOException $e) {
echo $e->getMessage();
}
}
$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg');
你在哪里分配$this->photo?它不在这里的片段中的任何地方。。。事实上,您正在将所有值作为参数传递给该方法,但没有实际使用它们。您在哪里分配$this->photo?它不在这里的片段中的任何地方。。。事实上,您正在将所有值作为参数传递给该方法,但实际上并没有使用它们