常用的php ADODB使用方法集锦

2019-04-10 23:01:30王旭

$sql = "Delete FROM table Where id=2";        
$db->Execute($sql);        

// 取单个记录        
//$db->GetRow($sql), 取第一条记录,并返回一个数组,出错返回false        
$sql = "Select username,password,user_type FROM table Where id=3";        
$data_ary = $db->GetRow($sql);        
if ($data_ary == false) {        
    echo '没有找到此记录';        
    exit();        
} else {        
    echo $data_ary['username'] . ' ' . $data_ary['password'] . ' ' . $data_ary['user_type'] . '<br>';        
}        

//另一种方法        
$sql = "Select username,password,user_type FROM table Where id=3";        
if (!$rs = $db->Execute($sql)) {        
    echo $db->ErrorMsg();        
    $db->Close();        
    exit();        
}        
if (!$result = $rs->FetchRow()) {        
    echo '没有找到此记录';        
    exit();        
} else {        
    echo $result['username'] . ' ' . $result['password'] . ' ' . $result['user_type'] . '<br>';        
}        

// 取单个字段        
//$db->GetOne($sql) 取出第一条记录的第一个字段的值,出错则返回false        
$sql = "Select COUNT(id) FROM table";        
$record_nums = $db->GetOne($sql);        
相关文章 大家在看