Boo-urns Posted February 6, 2009 Share Posted February 6, 2009 <?php class db extends MySQLi { // some vars public function insertQuery($table, $fields, $values) { // Insert into table function; // Field processing (separating string, adding proper syntax to the field as well $fVal = ''; // field value for the insert query $insertFields = explode(", ", $fields); // separating the field string $fCount = count($insertFields); $i = 1; foreach ($insertFields as $fieldVal) { $fVal .= ($i < $fCount) ? "`$fieldVal`, " : "`$fieldVal`"; $i++; } // end of field processing // value processing // pretty much same as above code $val = ''; $values = explode(", ", $values); $vCount = count($values); $j = 1; foreach ($values as $v) { $val .= ($j < $vCount) ? "'$v', " : "'$v'"; $j++; } // end of value processing // INSERTING INTO DB STRING $insert = "INSERT INTO ". $table ." ( ". $fVal ." ) VALUES ( ". $val . " )"; mysqli::query($insert); } // end of insertQuery } So my problem is the query. It's not querying the mysqli query function. I have errors being displayed but its not giving me any problems. What am I doing wrong? -Corey Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/ Share on other sites More sharing options...
premiso Posted February 6, 2009 Share Posted February 6, 2009 I am not familiar with mysqli but try this: mysqli::query($insert) or die("ERROR IN SQL: $insert <br /> ERROR MSG: " . mysqli::error() ); And see if that spits out an error or not. Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756176 Share on other sites More sharing options...
Boo-urns Posted February 6, 2009 Author Share Posted February 6, 2009 Yea it does spit out an error: Fatal error: Call to undefined method mysqli::error() Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756180 Share on other sites More sharing options...
premiso Posted February 6, 2009 Share Posted February 6, 2009 Maybe I used it in the wrong way, sorry. Like I said I am not familiar with the mysqli class: mysqli::query($insert) or die("ERROR IN SQL: $insert <br /> ERROR MSG: " . mysqli->error() ); See if that does anything different... Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756185 Share on other sites More sharing options...
Boo-urns Posted February 6, 2009 Author Share Posted February 6, 2009 I believe the first way was correct as since it is in the class you can't call it the straight up object way. Parse error: syntax error, unexpected T_OBJECT_OPERATOR Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756188 Share on other sites More sharing options...
premiso Posted February 6, 2009 Share Posted February 6, 2009 Yea, I am just digging a hole for myself. I am not sure how your class or the mysqli class work exactly. So instead of guessing again I would highly suggest you read up on the MySQLi class particularly on method Mysqli->error. Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756193 Share on other sites More sharing options...
Boo-urns Posted February 6, 2009 Author Share Posted February 6, 2009 I resorted to trying it out not in the extended class and straight from the mysqli class. That did show errors and I had an error in the query. I did get it fixed in the class though with this: <?php if (!mysqli::query($insert)) { printf("Errormessage: %s\n", $this->error); } For some reason it wouldn't recognize the mysqli parent class. Link to comment https://forums.phpfreaks.com/topic/144107-solved-extending-mysqli-class-not-querying/#findComment-756234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.