当前位置:Gxlcms > 数据库问题 > php 连接mysql(查询 增删改)

php 连接mysql(查询 增删改)

时间:2021-07-01 10:21:17 帮助过:15人阅读


    $dbh->exec("Insert INTO `test`.`table` (`name` ,`age`)VALUES (‘mick‘, 22);");  
    $dbh->exec("Insert INTO `test`.`table` (`name` ,`age`)VALUES (‘lily‘, 29);"); 
    $dbh->exec("Insert INTO `test`.`table` (`name` ,`age`)VALUES (‘susan‘, 21);");  
    $dbh->commit(); 
 } catch (Exception $e) {  
    $dbh->rollBack();  
    echo "Failed: " . $e->getMessage();  
 } 

 

4.foreach语句

<?php
$dbh->query($sql); 当$sql 中变量可以用$dbh->quote($params); //转义字符串的数据
$sql = ‘Select * from city where CountryCode =‘.$dbh->quote($country);  //引用
foreach ($dbh->query($sql) as $row)   {    
 print $row[‘Name‘] . "/t";    
 print $row[‘CountryCode‘] . "/t";    
 print $row[‘Population‘] . "/n"; 

?>

 

php 连接mysql(查询 增删改)

标签:连接数   set   let   color   波浪   tin   转义字符   转义   led   

人气教程排行