在PHP中有没有像ASP中的记录集(ADODB.Recordset )这种类型的对象?可不可以像在ASP中一样通过记录集来更新数据库.如下面这样. set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
rs.addnew
rs("字段名")=值
rs.update
rs.close
set rs=nothing难道只能用insert语句吗?
rs.open sql,conn,3,2
rs.addnew
rs("字段名")=值
rs.update
rs.close
set rs=nothing难道只能用insert语句吗?
$rs->open($sql, $conn, 3, 2);
$rs->addnew();
$rs("字段名") = 值;
$rs->update();
$rs->close();
adoconn.Open"Driver={Microsoft Access Driver(*.mdb)};DBQ="&Server.MapPath("数据库所在路径") set rs=server.createobject("adodb.recordset")
rs.open "select * from table ", adocon, 1,1
if not rs.eof then
.....等操作php:$user = "user1"; /用户名
$passwd = "testing"; /密码
$connect = mysql_connect('localhost', 'user1', 'testing')
or die('Could not connect: ' . mysql_error());
/连接mysql服务器
mysql_query("SET NAMES 'GB2312'",$connect); //中文
mysql_select_db('dbname') //选择指定的数据库
$sql = mysql_array('select * from table ');
$result = mysql_fetch_array($sql);
if ($result != flase){
....
}
结果集取得的行生成数组
PHP里面没有 但是ZendFramework里面有 Zend_Db_Table
当得到一个数据结果为一个rowset对象时
可以做几乎一样的操作
xuzuning,你雷到我了,这样也可以?????真的好新鲜...
如果你的PHP是在WIN下面跑的,不仅adodb.recordset对象,一切可以用ASP server.createobject 创建的对象都可以用类似的代码来做,比如:function getContentPost($strURL,$strData){
try{
$tmpObject = @new COM("Msxml2.XMLHTTP");
}catch (Exception $e){
$tmpObject = @new COM("Microsoft.XMLHTTP");
}
$tmpObject->Open("Post",$strURL,False,"","");
$tmpObject->setRequestHeader("Content-Type","application/x-www-form-urlencoded");
$tmpObject->Send($strData);
$re = $tmpObject->ResponseBody();
return toByte2StringCharset($re,"utf-8");
}
Function toByte2StringCharset($strer,$strCharset){
$tmpObject = @new COM("ADODB.Stream");
$tmpObject->Type=1;
$tmpObject->Mode=3;
$tmpObject->Open();
$tmpObject->Write($strer);
$tmpObject->Position=0;
$tmpObject->Type=2;
$tmpObject->Charset=$strCharset;
$re=$tmpObject->ReadText();
return $re;
}
* 返回用户全部信息
* @param $id
*/
function get_info_more($id)
{
$this->db->select('user.*,dict_province.s_provname,dict_city.s_cityname');
$this->db->from('user');
$this->db->join('dict_province','dict_province.n_provid=user.city1','left');
$this->db->join('dict_city','dict_city.n_cityid=user.city2','left');
$this->db->where('user.id',$id);
$r=$this->db->get();
return $r->row();
}
/**
* 返回用户基本信息
* @param $id
*/
function get_free_money($id){
$this->db->select('free_money');
$this->db->from('user');
$this->db->where('id',$id);
$r=$this->db->get();
return $r->row_array();
}
/**
* 更新用户密码
* @param int $id
* @param string $pwd
*/
function update_pwd($id,$pwd)
{
$this->db->set('pwd',md5(md5('gsehgsheig'.$pwd)));
$this->db->where('id',$id);
$this->db->update('user');
}
/**
* 更新用户基本信息
* @param int $id
* @param string $real_name
* @param string $tel
* @param string $pwdq
* @param string $pwda
* @param string $mail
* @param int $city1
* @param int $city2
*/
function update_info($id,$real_name,$tel,$pwdq,$pwda,$mail,$city1,$city2){ $this->db->set('real_name',$real_name);
$this->db->set('tel',$tel);
$this->db->set('pwdq',$pwdq);
$this->db->set('pwda',$pwda);
$this->db->set('mail',$mail);
$this->db->set('city1',$city1);
$this->db->set('city2',$city2);
$this->db->where('id',$id);
$this->db->update('user');
}
/**
* 新注册用户
* @param string $u
* @param string $p
* @param int $type
* @param string $real_name
* @param string $tel
* @param string $pwdq
* @param string $pwda
* @param string $mail
* @param int $city1
* @param int $city2
*/
function new_user($u,$p,$type,$real_name,$tel,$pwdq,$pwda,$mail,$city1,$city2){
$this->db->set('user',$u);
$this->db->set('pwd',md5(md5('gsehgsheig'.$p)));
$this->db->set('type',$type);
$this->db->set('real_name',$real_name);
$this->db->set('tel',$tel);
$this->db->set('pwdq',$pwdq);
$this->db->set('pwda',$pwda);
$this->db->set('mail',$mail);
$this->db->set('reg_date',date('Y-m-d H:i:s'));
$this->db->set('login_date',date('Y-m-d H:i:s'));
$this->db->set('city1',$city1);
$this->db->set('city2',$city2);
$this->db->insert('user'); }
/**
* 检验用户名是否注册
* @param string $user
*/
function is_reg($user){
$this->db->select('pwd');
$this->db->from('user');
$this->db->where('user',$user);
$r=$this->db->get();
return $r->num_rows>0;
}
/**
* 用户登录
* @param string $u
* @param string $p
*/
function login($u,$p){
$this->db->select('id,type');
$this->db->from('user');
$this->db->where('user',$u);
$this->db->where('pwd',md5(md5('gsehgsheig'.$p)));
$r=$this->db->get();
if($r->num_rows==0) return false;
$this->session->set_userdata('is_login',TRUE);
$this->session->set_userdata('user',$u);
$result=$r->result();
$this->session->set_userdata('userid',$result[0]->id);
$this->session->set_userdata('usertype',$result[0]->type);
return true;
}
}