PHP技术那点事
全部
技术
PHP
MySQL
前端
Linux
JAVA
退出
编辑文章
选择分类
PHP
MySQL
前端
Linux
Java
工具
选择专栏
设计模式
java基础
Angular学习
Java面试题
描述:
封面图上传 :
+
点击上传图片
1、记录 SQL 查询语句 // 开启 log DB::connection()->enableQueryLog(); // 获取已执行的查询数组 DB::getQueryLog(); 2、数据库事务处理 // 开启事务 如果连接的不是默认库 一定要加上connection() DB::beginTransaction(); // 回退事务 如果连接的不是默认库 一定要加上connection() DB::rollBack(); // 提交事务 如果连接的不是默认库 一定要加上connection() DB::commit(); 3、查询数据集单列的数据 DB::table('name')->pluck('column'); 4、Order By, Group By, 和 Having $users = DB::table('users') ->orderBy('name', 'desc') ->groupBy('count') ->having('count', '>', 100) ->get(); DB::table('name')->orderBy('column')->get(); DB::table('name')->orderBy('column','desc')->get(); DB::table('name')->having('count', '>', 100)->get(); 5、原始表达句 $users = DB::table('users') ->select(DB::raw('count(*) as user_count, status')) ->where('status', '<>', 1) ->groupBy('status') ->get(); // 返回行 DB::select('select * from users where id = ?', array('value')); DB::insert('insert into foo set bar=2'); DB::update('update foo set bar=2'); DB::delete('delete from bar'); // 返回 void DB::statement('update foo set bar=2'); // 在声明语句中加入原始的表达式 DB::table('name')->select(DB::raw('count(*) as count, column2'))->get(); Inserts / Updates / Deletes / Unions / Pessimistic Locking // 插入 DB::table('users')->insert( ['email' => 'john@example.com', 'votes' => 0] ); $id = DB::table('users')->insertGetId( ['email' => 'john@example.com', 'votes' => 0] ); DB::table('users')->insert([ ['email' => 'taylor@example.com', 'votes' => 0], ['email' => 'dayle@example.com', 'votes' => 0] ]); // 更新 DB::table('users') ->where('id', 1) ->update(['votes' => 1]); DB::table('users')->increment('votes'); DB::table('users')->increment('votes', 5); DB::table('users')->decrement('votes'); DB::table('users')->decrement('votes', 5); DB::table('users')->increment('votes', 1, ['name' => 'John']); // 删除 DB::table('users')->where('votes', '<', 100)->delete(); DB::table('users')->delete(); DB::table('users')->truncate(); // 集合 // unionAll() 方法也是可供使用的,调用方式与 union 相似 $first = DB::table('users')->whereNull('first_name'); $users = DB::table('users')->whereNull('last_name')->union($first)->get(); // 消极锁 DB::table('users')->where('votes', '>', 100)->sharedLock()->get(); DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get(); 7、PHP生成唯一有序ID // 使用php自带uniqid()方法 static public function getUniId ($prefix = 'e_', $suffixLength = 8) { return uniqid($prefix, false) . '_' . Utils::generateRandomCode($suffixLength, 'ALL'); } // 随机数 static public function generateRandomCode ($len = 6, $format = 'NUMBER') { switch ($format) { case 'ALL': $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break; case 'CHAR': $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break; case 'NUMBER': $chars = '0123456789'; break; default : $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break; } // mt_srand((double)microtime() * 1000000 * getmypid()); $code = ""; while (strlen($code) < $len) { $code .= substr($chars, (mt_rand() % strlen($chars)), 1); } return $code; } // 由于生成的时候时间微秒级别 程序执行太快 要在getUniId()前加上 若干个前导0 8、php如何判断设备是不是移动端 9、表单验证 \"\"])*$/",$str))?true:false; } 9、simplexml_load_string函数的使用 输入:
Tove
Jani
Reminder
Don't forget me this weekend! XML; $xml=simplexml_load_string($note); print_r($xml); ?> 输出: SimpleXMLElement Object ( [to] => Tove [from] => Jani [heading] => Reminder [body] => Don't forget me this weekend! )
保存文章