zoukankan      html  css  js  c++  java
  • strstr() strpos() 获取db报错,判断报错中是否包含字符串,判断错误类型

    model中直接获取添加公司的错误.(公司名称不能重复)

    $enterprise_id = $this->add($enterprisedata );

    $err = $this->getDbError();

    $err =="1062:Duplicate entry 'aaa' for key 'enterprise_name' [ SQLu8bedu53e5 ] : INSERT INTO `t_enterprise` (`enterprise_name`,`enterprise_addtime`,`enterprise_account_id`) VALUES ('aaa','2016-06-11 16:39:20','23666')"

    $num = strstr($err,'Duplicate');  //字符串中,包含字符串.返回从Duplicate开始到结尾的字符串
    var_dump($num);

    $num = strpos($err,'Duplicate');   //字符串中,出现Duplicate的位置.5

    都是,在字符串中(第一个参数),,,,查找出现的字符串(第二个参数)

    $num =  explode('Duplicate',$err); //使用xxx字符串,分割字符串(第二个参数)

  • 相关阅读:
    css--盒子模型
    目标爬取社会信用码
    KFC-位置分页爬虫
    百度翻译-爬虫
    网页采集器-UA伪装
    python模块2
    python模块
    go入门
    python垃圾回收机制
    Python高级用法
  • 原文地址:https://www.cnblogs.com/bj-tony/p/5575538.html
Copyright © 2011-2022 走看看