Lamez Posted October 3, 2010 Share Posted October 3, 2010 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 More sharing options...
KevinM1 Posted October 3, 2010 Share Posted October 3, 2010 A -1 means the query returned an error. Link to comment https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/#findComment-1118561 Share on other sites More sharing options...
Lamez Posted October 4, 2010 Author Share Posted October 4, 2010 Oh, thanks so much! I will look over my query. Link to comment https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/#findComment-1118973 Share on other sites More sharing options...
Lamez Posted October 6, 2010 Author Share Posted October 6, 2010 I have looked my query up and down, I cannot find a mistake anywhere. Link to comment https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/#findComment-1119604 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2010 Share Posted October 6, 2010 Your code produces a query that looks like this (missing the WHERE keyword) - SELECT email FROM table_name email = '[email protected]' Did you really look at your query? Link to comment https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/#findComment-1119625 Share on other sites More sharing options...
KevinM1 Posted October 6, 2010 Share Posted October 6, 2010 Have you: Run the query directly (e.g., within phpMyAdmin)? Tested to see if your mySQLi object is actually being constructed and populated correctly? Turned on all error reporting? Link to comment https://forums.phpfreaks.com/topic/215023-help-with-my-email-class/#findComment-1119626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.