Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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