PHP
·
发表于 5年以前
·
阅读量:8305
±¾ÎÄʵÀý½²ÊoÁËphpÊÂÎñ»Ø¹o¼oµ¥ÊµÏÖ½¨¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
$servername="localhost";
$username="root";
$password="admin";
$dbname="test";
try{
$conn=new PDO("mysql:host=$servername;dbname=$dbname",$username,$password);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
//¿ªÊ¼ÊÂÎñ
$conn->beginTransaction();
$conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','XIAMING','yexianming@163.com')");
$conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','CONG','yecong@163.com')");
$conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('FANG','MENG','fangmeng@168.com')");
//Ìa½»ÊÂÎñ
$conn->commit();
echo "New records created successfully!";
}catch(PDOException $e){
//»Ø¹oÊÂÎñ
$conn->rollBack();
echo $sql."<br>".$e->getMessage();
}
$conn=NULL;
¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶MySQLÊÂÎñ²Ù×÷¼¼ÇÉ»a×Ü¡¡¢¡¶phpÃaeÏo¶ÔÏo³ÌÐoÉe¼ÆÈeÃŽ̡̳¡¢¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶[PHP»u±¾Ói¨ÈeÃŽ̳Ì](http://www.jb51.net/Special/348.htm)¡¡¢¡¶[PHPÔËËaÓeÔËËauÓè×ܽa](http://www.jb51.net/Special/357.htm)¡¡¢¡¶PHPÍøÂç±a³Ì¼¼ÇÉ×ܽa¡¡¢¡¶[php×Öu´®(string)Óè×ܽa](http://www.jb51.net/Special/47.htm)¡¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£