Jump to content

[SOLVED] Extending mysqli class not querying...


Boo-urns

Recommended Posts

<?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

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...

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.