Edit: I've added usage example and a clearer explanation of the code
snippet.
Catchable fatal error: Object of class stdClass could not be converted
to string in <filename> on line <line>
************************************************************ *****
I can only find the change log for PHP 5.2 identifying this type of
error, nothing on how to fix it. I have updated PHP to 5.2.3 on Apache
2.2.x on a BSD Box 6.x If some one could explain to me what I am doing
wrong, and what I need to do to fix it that would be swell.
A point of note is that my $dbh is being created in my class constructor
as a private. The method that is calling the prepare and execute
statements is a public. I don't thing I'm trying to do anything new or
exotic, I don't think I'm trying to convert the object to a string, just
execute the query statement....
//code snip of public function insertUser()
$begin = $this->dbh->beginTransaction();
if (!$begin) throw new HWIException(ERR0023,23);
$outdc = "";
$outliid = "";
$prep_users = $this->dbh->prepare($sql_users);
if (!$prep_users) {
$msg = $this->dbh->errorInfo();
throw new HWIException(ERR0021 . " " . $msg[2], 21);
}
$prep_users->bindParam(':username', $this->userObj->hwi_username,
PDO::PARAM_STR, 16);
$prep_users->bindParam(':title', $this->userObj->hwi_title,
PDO::PARAM_STR, 4);
$prep_users->bindParam(':firstname', $this->userObj->hwi_firstname,
PDO::PARAM_STR, 30);
$prep_users->bindParam(':midinit', $this->userObj->hwi_midinit,
PDO::PARAM_STR, 1);
$prep_users->bindParam(':lastname', $this->userObj->hwi_lastname,
PDO::PARAM_STR, 45);
$prep_users->bindParam(':priphone', $this->userObj->hwi_priphone,
PDO::PARAM_STR, 30);
$prep_users->bindParam(':priext', $this->userObj->hwi_priext,
PDO::PARAM_STR, 10);
$prep_users->bindParam(':secphone', $this->userObj->hwi_secphone,
PDO::PARAM_STR, 30);
$prep_users->bindParam(':secext', $this->userObj->hwi_secext,
PDO::PARAM_STR, 10);
$prep_users->bindParam(':fax', $this->userObj->hwi_fax, PDO::PARAM_STR,
30);
$prep_users->bindParam(':isPI', $this->userObj->hwi_ispi,
PDO::PARAM_INT);
$prep_users->bindParam(':date_returned', $outdc, PDO::PARAM_STR);
$prep_users->bindParam(':liid', $outliid, PDO::PARAM_STR);
##################### PROBLEM LINE OF CODE ###################
$exec = $prep_users->execute();
############################################################ #####
if(!$exec) {
$msg = $prep_users->errorInfo();
throw new HWIException(ERR0022 . " " . $msg[2], 22);
}
************************************************************ ****
USAGE
test.php
************************************************************ ****
$userobject->username = 'mysuername';
$userobject->lastname = 'mylastname';
// continue on w/ each property as described in the bindParam statements
in the insertUser() method.
//class MyUser extends PDO (I started out extending PDO, changed to code
to debug it by creating a $dbh object in the constructor, and switched
back to extending PDO. Nothing works.
$userObj = new MyUser($userObject);
$userObj->insertUser();
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php