View Single Post
ישן 30-01-11, 12:47   # 1
morsrh
חבר מתקדם
 
morsrh's Avatar
 
מיני פרופיל
תאריך הצטרפות: Feb 2010
מיקום: אשקלון.
גיל: 31
הודעות: 444
שלח הודעה באמצעות MSN אל morsrh

morsrh לא מחובר  

Exclamation בניית שאילתה [דחוף].

שלום ,
אני בונה מחלקה שתעבוד על מאגרי נתונים מסוג 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)-$i >= $i--){
                
$this->syntax .= '`'.$column[$i].'`';
                if(
$i != )
                    
$this->syntax .= ' , ';
                else
                    
$this->syntax .= ') VALUES (';
            }
            for(
$i count($column)-$i >= $i--){
                
$this->syntax .= '\''.$value[$i].'\'';
                if(
$i != )
                    
$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);
מה הבעיה פה חברה?
תודה.
  Reply With Quote