Jump to content
php.lv forumi

get_object_vars


gaziks52

Recommended Posts

tātad man ir klase User ... ar atribūtiem id, username un password, lieta tā ka es tajā kverijā create() metodē keyus un vērtības ģenerēju dinamiski bet lieta tā ka tā darot tur tiks iekļauts arī id atribūts bet tas nav vajadzīgs jo id ir auto_increment, tātad kā var panākt to lai tas id tai kverijā netiek iekļauts ???

 

 

class User {

public $id;
public $username;
public $password;

protected function attributes() {
return get_object_vars($this);
}

public function create() {
	global $database;
	$attributes = $this->attributes();
	$sql = "INSERT INTO users (";
	$sql .= join(", ", array_keys($attributes));
	$sql .= ") VALUES ('";
	$sql .= join("', '", array_values($attributes));
	$sql .= "')";
	if($database->query($sql)) {
	$this->id = $database->insert_id();
	return true;
	} else {
		return false;
	}
}		
}

 

problēma atrisināta :)

Edited by gaziks52
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...