Jump to content

Help with my Email Class.


Lamez

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;
			}else
				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:

<?php
    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;
            if(!$error)
                $result = $this->mysqli->query($query, $mode);
            else
                $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;
            }else
                $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){
            if(is_null($where))
                $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
https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/
Share on other sites

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.