按照下面的例子..。
public function insert($model,$brand,$price){
mysql_query("INSERT INTO autos (model, brand, price) VALUES ($model,'$brand', $price)",$this->link);}
$conexion-> insert(05,"Ford",50000000);...I编写了一个修改/更新代码:
public function modify($model,$brand,$price,$newbrand,$newprice){
mysql_query("UPDATE 'crautos'.'autos' SET 'brand' = '$newbrand',
'price' = '$newprice' WHERE 'autos'.'model' =5 AND 'autos'.'brand' = '$brand' AND 'autos'.'price' ='$price' LIMIT 1) VALUES ($newbrand, $newprice)",$this->link);}
$conexion-> modify("Mitsubishi", 40000000);但是它没有工作,这是错误输出:
警告:MyDataBase缺少参数3::modify(),在第15行警告中被调用:MyDataBase::modify()缺少参数4,在第28行中调用,在第15行警告中定义:缺失参数5用于MyDataBase::modify(),在第28行调用,在第15行中定义,以及未定义的变量新价格、新品牌、价格。插入代码很好,修改代码导致了问题。
下面是完整的代码:
<?php
class MyDataBase{
private $link;
public function __construct($server,$user,$password,$base){
//Conectar
$this->link = mysql_connect($server,$user,$password);
mysql_select_db($base,$this->link);
}
public function insert($model,$brand,$price){
mysql_query("INSERT INTO autos (model, brand, price) VALUES ($model,'$brand', $price)",$this->link);}
public function modify($model,$brand,$price,$newbrand,$newprice){
mysql_query("UPDATE 'crautos'.'autos' SET 'brand' = '$newbrand',
'price' = '$newprice' WHERE 'autos'.'model' =5 AND 'autos'.'brand' = '$brand' AND 'autos'.'price' ='$price' LIMIT 1) VALUES ($newbrand, $newprice)",$this->link);}
public function __destruct(){
//desconectar
}
}
$conexion = new MyDataBase ('localhost', 'root', '','crcars');
$conexion-> insert(05,"Ford",50000000);
$conexion-> modify("Mitsubishi", 40000000);
?>发布于 2011-08-05 18:41:57
更新查询中有无效的语法。你不需要价值观部分。应该是这样的:
mysql_query("UPDATE 'crautos'.'autos' SET 'brand' = '$newbrand', 'price' = '$newprice' WHERE 'autos'.'model' =5 AND 'autos'.'brand' = '$brand' AND 'autos'.'price' ='$price' LIMIT 1");发布于 2011-08-05 19:04:19
您的更新语法是无效的,就像@Martin指出的那样,您也是用两个参数调用modify(),但是函数需要5。
类似于:
$conexion-> modify("Mitsubishi", 40000000, $price, $newbrand, $newprice);https://stackoverflow.com/questions/6961050
复制相似问题