一、初始化连接
$db = new \workerman\mysql\connection('host', 'port', 'ur', 'password', 'db_name');
二、获取所有数据
$db->lect('id,x')->from('persons')->where('x= :x and id = :id')->bindvalues(array('x'=>'m', 'id' => 1))->query();//等价于$db->lect('id,x')->from('persons')->where("x= 'm' and id = 1")->query();//等价于$db->query("lect id,x from `persons` wh爱是你我歌词下载ere x='m' and id = 1");
三、获取一行数据
$db-&一顿相当于多少千克gt;lect('id,x')->from('persons')->where('x= :x')->bindvalues(array('x'=>'m'))->row();//等价于$db->lect('id,x')->from('persons')->where("x= 'm' ")->row();//等价于$db->row("lect id,x from `persons` where x='m'");
四、获取一列数据
$db->lect('id')->from('persons')->where('x= :x')->bindvalues(array('x'=>'m'))->column();//等价于$db->lect('id')->from('persons')->where("x= 'f' ")->column();//等价于$db->column("lect `id` from `persons` where x='m'");
五、获取单个值
$db->lect('id')->from('persons')->where('x= :x')->bindvalues(array('x'=>'m'))->single();//等价于$db->lect('id')->from('persons')->where("x= 'f' ")->single();//等价于$db->single("lect id from `persons` where x='m'");
六、复杂查询
$db->lect('*')->from('table1')->innerjoin('table2','table1.uid = table2.uid')->where('age > :age')->groupby(array('aid'))->having('foo="foo"')->orderbyasc/*orderbydesc*/(array('did'))->limit(10)->offt(20)->bindvalues(array('age' => 13));// 等价于$db->query('lect * from `table1` inner join `table2` on `table1`.`uid` = `table2`.`uid`where三仙台 age > 13 group by aid having foo="foo" order by did limit 10 offt 20');
七、插入数据
$inrt_id = $db->inr伯利克t('persons')->cols(array( 'firstname'=>'abc', 'lastname'=>'efg', 'x'=>'m', 'age'=>13))->query();等价于$inrt_id = $db->query("inrt into `persons` ( `firstname`,`lastname`,`x`,`age比较好`)values ( 'abc', 'efg', 'm', 13)");
八、更新数据
$row_count = $db->update('persons')->cols(array('x'))->where('id=1')->bindvalue('x', 'f')->query();// 等价于$row_count = $db->update('persons')->cols(array('x'=>'f'))->where('id=1')->query();// 等价于$row_count = $db->query("update `persons` t `x` = 'f' where id=1");
九、删除数据
$row_count = $db->delete('persons')->where('id=9')->query();// 等价于$row_count = $db->query("delete from `persons` where id=9");
十、事务处理
$db->begintrans();....$db->committrans(); // or $db->rollbacktrans();
本文发布于:2023-04-07 07:13:55,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/e9153f0e5ab4bae197e21c30806f3918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Workerman MySQL组件Connection用法总结.doc
本文 PDF 下载地址:Workerman MySQL组件Connection用法总结.pdf
留言与评论(共有 0 条评论) |