[Solved] Stuck In Prepared Statement code
Posted: Fri Sep 03, 2010 1:29 pm
Hello, once again i am stuck, once again the problem i am stuck on seems to not be documented on at all any where.
So, i have some code in a class that creates an object of another class and passes some data to this class. The newly created class then runs a stored procedure to a database. The example i am about to give is for inserting some user deatails into the database to create a new user.
This is the function that controls it.
This is the function that it is calling.
So what happens at the moment is that basically nothing, nothing is created in the database. I do however get the first error email of the two.
So i really do not now what is going on. Sorry that this is a long piece of code, i have tried to solve it myself but it has beaten me.
Many Thanks
Chris
So, i have some code in a class that creates an object of another class and passes some data to this class. The newly created class then runs a stored procedure to a database. The example i am about to give is for inserting some user deatails into the database to create a new user.
This is the function that controls it.
Code: Select all
public function addUserDetails()
{
$userFirstName = $this->_filtered['userFirstName'];
$userLastName = $this->_filtered['userLastName'];
$userMail = $this->_filtered['userMail'];
$userPassword = $this->_filtered['userPassword'];
$query = "INSERT INTO userDetails (userFirstName, userLastName, userMail, userPassword) VALUES (?, ?, ?, ?)";
$tempVal = $this->_DBConnection->runQuery($query, array(&$userFirstName, &$userLastName, &$userMail, &$userPassword), false);
if($this->_DBConnection->getLastID() == false) {
mail("bugs@site.co.uk", "Major Error In Creating User", "Please Check Tables For Creating A User. Error in 'register_CreateUser.php' on 'line 79'. Paramaters(UserName = $userFirstName $userLastName, UserMail = $userMail)", "From: code@site.co.uk");
return false;
}
else $this->_userID = $this->_DBConnection->getLastID();
$query2 = "INSERT INTO userActive (userID, userLastSeen, userHash) VALUES (?, ?, ?)";
$userLastSeen = date("M jS Y");
$this->_userHash = md5(uniqid(rand(), true));
$tempVal2 = $this->_DBConnection->runQuery($query2, array(&$this->_userID, &$userLastSeen, &$this->_userHash), false);
if($this->_DBConnection->getLastID() == false || $this->_DBConnection->getLastID() != $this->_userID) {
mail("bugs@site.co.uk", "Major Error In Creating User", "Please Check Tables For Creating A User. Error in 'register_CreateUser.php' on 'line 88'. Paramaters(UserName = $userFirstName $userLastName, UserMail = $userMail)", "From: code@site.co.uk");
return false;
}
$this->_DBConnection->close();
return true;
}
Code: Select all
public function runQuery($query, $functionArray = array(), $needResults = true)
{
$stmtParam = "";
$parameters = array();
$results = array();
foreach ($functionArray as $v) {
$stmtParam .= "s";
}
array_unshift($functionArray, $stmtParam);
$stmt = $this->_dbConnection->prepare($query);
call_user_func_array(array($stmt, 'bind_param'), $functionArray);
$stmt->execute();
if($needResults) {
$meta = $stmt->result_metadata();
while ( $field = $meta->fetch_field() ) {
$parameters[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $parameters);
while ( $stmt->fetch() ) {
$x = array();
foreach( $row as $key => $val ) {
$x[$key] = $val;
}
$results[] = $x;
}
return $results;
} else return true;
}
So i really do not now what is going on. Sorry that this is a long piece of code, i have tried to solve it myself but it has beaten me.
Many Thanks
Chris