Jump to content

Help with my Email Class.


Recommended Posts

I am currently working on my email class, it works but I am do slight modifications to make it a little better.

Here is the function I am working on:

	function addAccount($name, $email, $username, $password, $protocol, $port, $server){
		if(!empty($name) && !empty($email) && !empty($username) && !empty($password) && !empty($protocol) && !empty($port) && !empty($server)){
			echo $this->db->select(TBL_SMTP, "email", "email = '$email'")->numRows();// This line here returns -1
			if($this->db->select(TBL_SMTP, "email", "email = '$email'")->numRows() == 0){
				$name = ucwords(strtolower($name));
				$email = strtolower($email);
				$this->db->execute("INSERT INTO ".TBL_SMTP." (name, email, username, password, protocol, port, server) VALUES ('$name', '$email', '$username', '$password', '$protocol', '$port', '$server')");
				return true;
				return false;
		return false;


Notice the line I marked that said, this returns -1. Well I thought if it did not exist in the database, that it was suppose to return 0? Any help?


Oh here is my database class:

    class Database{
        var $mysqli, $result, $q, $affectedRows;
        function __construct($host, $user, $pass, $db){
            $this->mysqli = new MySQLi($host, $user, $pass, $db);
        function execute($query, $error = false, $mode = MYSQLI_STORE_RESULT){
            $this->q = $query;
                $result = $this->mysqli->query($query, $mode);
                $result = $this->mysqli->query($query, $mode) or die($this->mysqli->error);
            if(is_object($result) && $result instanceof MySQLi_Result){//if result is a object and is part of the mysqli class?
                $this->result = $result;
                $this->affectedRows = $this->result->num_rows;
                $this->affectedRows = $this->mysqli->affected_rows;
            return $this;
        function fetchRow($mode = MYSQLI_ASSOC){
            return $this->result->fetch_assoc($mode);
        function fetchAll($mode = MYSQLI_ASSOC){
            $row = $this->result->fetch_all($mode);
            return !empty($row) ? $row : array();//if not empty return row, else return an array?
        function numRows(){
            return $this->affectedRows;
        function delete($table, $where){
            return $this->execute("DELETE FROM ".$table." WHERE ".$where);
        function deleteAll($table){
            return $this->execute("TRUNCATE ".$table);
        function update($table, $set, $where){
            return $this->execute("UPDATE ".$table." SET ".$set." WHERE ".$where);
        function select($table, $select = "*", $where = NULL){
                $where = "";
            return $this->execute("SELECT ".$select." FROM ".$table." ".$where);
        function resetInc($table, $inc){
            $this->execute("ALTER TABLE ".$table." AUTO_INCREMENT = ".$inc);
    $db = new Database(DB_HOST, DB_USER, DB_PASS, DB_DB);


Hey, Thanks guys!

Link to comment
Share on other sites

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.

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.