This article mainly introduces the usage of the Symfony2 function, and analyzes the Symfony function call and database operation related skills based on the instance form. For more information, see the example in this article to describe the usage of the Symfony2 function. We will share this with you for your reference. The details are as follows:
1. Call methods of other objects.
Example:
$ Grobal_func = $ this-> container-> get ('Global _ func '); // name of the 'Global _ func' function $ lot_data = $ global_func-> getDataFromFile ($ parm1); // getDataFromFile function name
2. Database preparation Query
$conn = $this->em->getConnection();$sql_user="select * from lot_user where user_name=:param1 and user_id=:param2 limit 1";$params = array( 'param1' => $user, 'param2' => $uid);$ready = $conn->prepare($sql_user);$ready->execute($params);$result_user = $ready->fetchAll();
3. Database rollback events
$em->getConnection()->beginTransaction();try{ $lotuser = new LotUser(); $lotuser->setId(0); $lotuser->setUserId($user_id); $lotuser->setUserName($user_name); $lotuser->setPassword($password); $lotuser->setUserTele($user_tele); $lotuser->setEmail($email); $lotuser->setRegDate($reg_date); $lotuser->setIdNumber($id_number); $lotuser->setRealUsername($real_username);$em->persist($lotuser);$em->flush();$em->getConnection()->commit();}catch(Exception $e){$e->getConnection()->rollback();}
I hope this article will help you design PHP programs based on the Symfony framework.