1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9<?PHPTen One Try A { - $dsn= "Mysql:dbname=mydb;host=localhost"; MySQL is the driver name dbname database name host server address - the $pdo=NewPDO ($dsn, "root", "123"); Root database user name 123 database password - - } - Catch(pdoexception$e) + { - Echo"Connection error."$e-GetMessage (); + } A at //Enquiry - $sql= "SELECT * FROM Info"; - - $stmt=$pdo->prepare ($sql); - - $stmt-execute (); in - while($row=$stmt->fetch (PDO::fetch_num)) to { + Print_r($row); - Echo"<br>"; the } * $ Panax Notoginseng //Add - $SQLTJ= "INSERT into info values (: code,:name,:nation,:sex,:birthday)" ; the + $STTJ=$pdo->prepare ($SQLTJ); A the $STTJ->execute (Array("Code" = "p009", "name" = "Harry", "Nation" = "Miao", "Sex" =>0, "Birthday" and "1995-09-06")); + - $?> $</body> -Web page:
Database:
PDO Connection database exercise (to be repaired)