Prepared Statements and mySQL

From: Date: Mon, 27 Dec 2010 21:08:28 +0000
Subject: Prepared Statements and mySQL
Groups: php.db 
Request: Send a blank email to php-db+get-47569@lists.php.net to get a copy of this message
I am trying to implement Prepared Statements on my web site and this is the first time I have ever used this. #1) I received the error “class mysql not defined”. That is a reference to the first line of code (below) where the database connection is established. #2) How do I assign the auto_increment value to a variable use Prepared Statements? In the syntax I am attempting below “record” is an auto_increment column. #3) Do syntaxes such as “$stmt->bindParam(':account_suspended', 0000-00-00);” require the date 0000-00-00 to be surrounded by ‘ ? Thank you to the many of you who have supported me this year when I have had questions. I am physically handicapped, although I don’t want to make a big deal about it. I have appreciated the opportunity to continue developing my PHP / mySQL programming skills in 2010. The Internet is a life line to me. Ron $dbh = new mysql('localhost', '$username', '$password', '$database2'); $stmt = $dbh->prepare("INSERT INTO $database2.member ( record , first_name , last_name , address_1 , address_2 , address_3 , address_4 , address_5 , email , prayer_community_alias , birth_month , birth_day , pass , validated , last_login , last_activity , birthday_records , greeting_reference , registration_ip_address, account_created , account_suspended , account_closed , referral_source , friends_of_ministry_package , security_question_1 , security_answer_1 , security_question_2 , security_answer_2 , security_question_3 , security_answer_3 ) VALUES ( NULL , ':f1', ':l1', '', '', '', '', '', ':e1', '', ':birth_month', ':birth_day', ':validate_password', ':validated', ':last_login', ':last_activity', ':birthday_records', ':greeting_reference', ':registration_ip_address', ':account_created', ':account_suspended', ':account_closed', ':referral_source', ':friends_of_ministry_package', ':security_question_1', '', ':security_question_2', '', ':security_question_3', '' ) ON DUPLICATE KEY UPDATE validated = ':validated', pass = ':validate_password', account_suspended = ':account_suspended', account_closed = ':account_closed', last_activity = ':last_activity', registration_ip_address = ':registration_ip_address';"); $stmt->bindParam(':f1', $f1); $stmt->bindParam(':l1', $l1); $stmt->bindParam(':e1', $e1); $stmt->bindParam(':birth_month', 0); $stmt->bindParam(':birth_day', 0); $stmt->bindParam(':validate_password', $validate_password); $stmt->bindParam(':validated', 5); $stmt->bindParam(':last_login', $todays_date); $stmt->bindParam(':last_activity', $todays_date); $stmt->bindParam(':birthday_records', 15); $stmt->bindParam(':security_question_1', 0); $stmt->bindParam(':greeting_reference', 0); $stmt->bindParam(':registration_ip_address', $registration_ip_address); $stmt->bindParam(':account_created', $todays_date); $stmt->bindParam(':account_suspended', 0000-00-00); $stmt->bindParam(':account_closed', 0000-00-00); $stmt->bindParam(':referral_source', 2); $stmt->bindParam(':friends_of_ministry_package', 0); $stmt->bindParam(':security_question_1', $security_question_1); $stmt->bindParam(':security_question_2', $security_question_2); $stmt->bindParam(':security_question_3', $security_question_3); // insert one row $stmt->execute(); $stmt->close(); The Verse of the Day “Encouragement from God’s Word” http://www.TheVerseOfTheDay.info

« previous php.db (#47569) next »