שלום ,
אני בונה מחלקה שתעבוד על מאגרי נתונים מסוג MYSQLI ובניתי פונקציה שאמורה ליצור מחרוזת של שאילתה ואז לשלוח אותה , הנה מה שכתבתי:
PHP קוד:
$val[] = 'VH1';
$val[] = 'VH2';
$val[] = 'VH3';
$col[] = 'CL1';
$col[] = 'CL2';
$col[] = 'CL3';
$this->mysqliInsert($val , 'users' , $col);
function mysqliInsert($value , $table , $column){
if(is_array($column)){
if(count($column) != count($value)){
echo 'SERVER ERROR: while insert VALUE count does not equal COLUMN count';
exit;
}
$this->syntax = '"INSERT INTO `'.$table.'` ( ';
for($i = count($column)-1 ; $i >= 0 ; $i--){
$this->syntax .= '`'.$column[$i].'`';
if($i != 0 )
$this->syntax .= ' , ';
else
$this->syntax .= ') VALUES (';
}
for($i = count($column)-1 ; $i >= 0 ; $i--){
$this->syntax .= '\''.$value[$i].'\'';
if($i != 0 )
$this->syntax .= ' , ';
else
$this->syntax .= ')"';
}
echo $this->syntax;
}
$this->sqli->query->($this->syntax);
}
מה שיוצא בסוף זה :
קוד:
"INSERT INTO `users` ( `CL3` , `CL2` , `CL1`) VALUES ('VH3' , 'VH2' , 'VH1')"
בדיוק מה שתכננתי שיצא.
אבל כנראה שזה לא עובד..
השגיאה היא :
קוד:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in C:\wamp\www\rebi\server\mysqli_c.php on line 52
שורה 52 :
קוד:
$this->sqli->query->($this->syntax);
מה הבעיה פה חברה?
תודה.