新鸟初入PHP行业6个月总结心得

1.$_SERVER['HTTP_HOST']返回phpsdudy中设置的服务器地址:127.0.0.1  hml.367edu.cn

如果没有使用代理服务器,

  REMOTE_ADDR = 客户端IP    HTTP_X_FORWARDED_FOR = 没数值或不显示

  $ip = $_SERVER['REMOTE_ADDR'];

 

2.file_get_contents(test.txt)读取的结果是一个字符串;

file(test.txt)读取的结果是一个数组;

 

3.print_r($arr,true)返回一个包含完整数组内容的字符串.

 

4.file_put_contents(‘’test.txt’’,$arr)可以将数据库的数据写入一个文件中,可以只访问一次数据库,减少数据库压力.

 

5.通过对比,lock in share mode适用于两张表存在业务关系时的一致性要求,for update适用于操作同一张表时的一致性要求。

共享锁(S):SELECT * FROM table_name WHERE ... LOCK IN SHARE MODE

排他锁(X)SELECT * FROM table_name WHERE ... FOR UPDATE

 

6.include dirname(__FILE__).'/../hello.php';

dirnamedirname(__FILE__)./hello.php'; 相同。

 

7.导出数据库所有表:选中数据库psd1710,右键选择转储SQL文件,选择结构和数据(保留字段fields).

导入数据库所有表:新建一个本地数据库psd1709,右键选择运行SQL文件.

 

8.音频:audio  

  

  

  您的浏览器不支持 audio 元素。

 

 

 

 

 

 

9.find() 方法返回被选元素的后代元素。如:$("ul").find("span").css({"color":"red","border":"2px solid red"}); html部分:

    ul (直接父节点)  

  • li (子节点)

    span (孙节点)

  

 

 

10.readonly:html只读,输入框无法更改

 

 

11.连接数据库:

@1.mysqli方式

define('DB_HOST', "192.168.0.20");
define('DB_PORT', "3306");
define('DB_USER', "367edu");
define('DB_PASS', "123456");
define('DB_NAME', "367edu");

 

$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);

$sql = "select * from sc_student_query_category";

$result = mysqli_query($link, $sql);

$queryCategory = mysqli_fetch_all($result,MYSQLI_ASSOC);

 

 

  1. 数据库数据格式主要有几种:数字(int)(tinyint(decimal【适合于金额如decimal(10,2)】)  字符串(varchar(char)(text)(LONGTEXT)等    时间(TIMESTAMP一般使用int

 

  1. $(.class).attr(属性,值)可以动态改变元素的属性的值,如下:

$(".shang_payimg img").attr("src","https://static.runoob.com/images/dashang/"+dataid+"img.png");

 

14、$(#id).text(值)可以动态改变元素内的值,如下:$("#shang_pay_txt").text(dataid=="alipay"?"支付宝":"微信");

 

15.跳转到顶部或者尾部:<

a href="#pos" style="color: red;font-size: 50px;

position: relative; left: 600px;">↓↓↓↓跳到底部↓↓↓↓a>

 

  1. HTTP状态码:

1xx:信息类

2xx:成功类

3xx:重定向类

4xx:客户端错误类

5xx:服务端错误类

 

 

  1. URL地址去找控制器,先找到后台,然后在去找前台页面.  :

http://9469.367edu.com/?a=wap.article&uid=9469&id=179575先找后台,再去找前台. 没有前台则不会显示任何东西.

 

18.按照条件遍历整个表:

//主页视频加载
require_once $_SITE_PATH_."m/m_lib_users_media.php";
$m_lib_users_media = new m_lib_users_media();
$media = $m_lib_users_media->getArray($m_lib_users_media->startGet()->getByusers_id($__users_id__)->getByis_del(0)->setOrder('id desc')->limit(1)->query());

 

importDbModel("sc_wx_rule_app_users");
$m_sc_wx_rule_app_users = new m_sc_wx_rule_app_users($__users_id__);
$app_list = $m_sc_wx_rule_app_users->getPcAppList();

 

18.01增加数据

require_once  str_replace('ucenter','default',$_SITE_PATH_)."m/m_oa_notice_record.php";
$m_oa_notice_record =new m_oa_notice_record();

 

$_data = array(
    'users_id' => $__users_id__,
    'notice_id' => $vals_id,
    'teacher_id' => $tea_id,
    'create_date' => time()
);

$result_row = $m_oa_notice_record->save($_data)->query();

 

 

模型中操作数据库

public function getResourceListzl(){

$this->_ssql = "select r.id,r.mycolor,st.id as teacher_id, r.title, r.status, r.category_id, r.reback_content, r.publish, r.create_date, st.name as teacher_name, ss.title as subject_title, category.title as category_title from $this->source r left join sc_teacher st on st.id=r.teacher_id left join sc_subject ss on ss.id=r.subject_id left join resource_category category on category.id=r.category_id where $where  order by create_date desc LIMIT $offset, $obj->size";
$list = $this->getArray($this->query());

}

或者

$apply_list = $this->model->table("ls_property_apply", "apply")
   ->join("ls_property", "prop", "inner")->on("apply.prop_id=prop.id AND prop.is_del=0")
   ->join("ls_property_category", "cate", "inner")->on("prop.cate_id=cate.id AND cate.is_del=0")
   ->join("sc_teacher", "st", "inner")->on("apply.apply_teacher_id=st.id AND st.is_del=0")
   ->join("sc_teacher", "sst", "left")->on("apply.mg_teacher_id=sst.id AND sst.is_del=0")
   ->where($where_str, $parameter)
   ->order("apply.apply_time desc, apply.id desc")
   ->limit($offset, $size)
   ->findAll("apply.*, cate.title AS cate_title, prop.pnumber, prop.title AS prop_title, prop.company, prop.speci, st.name AS apply_teacher_name, sst.name AS mg_teacher_name");

 

 

 

 

 

 

$supplement_list = $this->model->table('oa_supplement_attend','attend')
            ->join("sc_teacher", "st", "left")->on('attend.teacher_id=st.id')
            ->where("attend.users_id = $__users_id__ and attend.is_del=0")
            ->order(' (case when attend.status=0 then 1 when attend.status=1 then 2 else 3 end),attend.create_date desc')
            ->findAll('st.name,attend.*');
return $supplement_list;

 

 

 

 


   增加数据库记录

$descriptionObj = new stdClass();
$descriptionObj->articles_id = $articlesInfo->id;
$descriptionObj->content = trim($articleContent);
$descriptionInfo = $m_articles_description->saveExpend($descriptionObj);

 

 

  1. 轮播图不起作用的时候是因为jQuery 加载了两次,而且jQuery 只能加载于所有JS之前.

 

19.微网导航小图标加载带的CSS是:

  web_3g_menu{ 数据库}如果该线上数据库中没有小图标字段,则不会显示.

 

 

  1. 账号:

东江广雅学校:ID9479 账号:djgyxx 密码:djgyxx163

绵阳东辰教育集团有限公司:ID9470 账号:mydcjyjt 密码:mydcjyjt163

 

 

 

 

 

 

 

 

 

 

  1. 数据采集如果走到了没有文章列表,肯定是本分类下文字列表头尾的标签没有写对.

//获取当前页面分类下的所有文章地址

$set_article_url_start = '

 

32.动态加载左边栏js: 

(function(){
        var url = self.location.href;
/*        var n = url.split("=").pop();
        console.log(n);
        if( !n ){ n=0 };*/
        try {
            $('#cont-ifr').attr('src', arr[0].list[0].src);
            var str = '

'+ arr[0].title +'

'+
                '
    ';
                for(var i=0;i                var active = i==0?'class="active"':'';
                    str += '
  • '+ arr[0].list[i].name +'
  • '
                }
                str += '
';
            $(".cont-left").html(str);
            console.log(str);
        } catch (e) {
            return false;
        }
    })();

33. html是替换,而append是追加
例如
内容

$(#div1").html("
这是内容
");

这样的最终结果就是
这是内容
//也就是把原来的内容替换了

$(#div1").append("
这是内容
");

这样的最终结果就是
内容
这是内容

34.申明一个二维的空数组:

$in = array('roomid'=>array(''));

 

  1. 调试接口里面的数据是在network里面查看XHR里面

 

  1. attr("width","500");
  2. css({"background-color":"yellow","font-size":"200%"})
  3. 选中所有多选框:
  4. $(":checkbox[name='ids']"),选中所有多选框$(":checkbox[name='ids']").prop("checked", this.checked); // this指代的你当前选择的这个元素的JS对象

 

 

39.选中所有ul下的li下的a标签:$('.cont-left .p-list').find("a")

 

40,腾讯云图片上传:

importClass('tencent_image');
$tencentImageClass = new tencentImage();   //云图上传
$yun_url = $tencentImageClass->upload($savePath, $__users_id__);

 

41.接口的正确写法:

$uploadPath =  $_ROOT_PATH_."/cache/img/".$__users_id__.'/oa/';
$fname = basename($_FILES['file']['name']);
$f = explode(".", $fname);
$extname = strtolower($f[count($f)-1]);
$rand = rand(1000, 9999);
$fileName = substr(time(),5).$rand.".$extname";
$folder = date("Y-m-d");
$src = $folder."/$fileName";
$savePath = $uploadPath.$src;
importClass('tencent_image');
$tencent_image = new tencentImage();
$result = $tencent_image->upload($savePath,$__users_id__);//上传到腾讯云的图片
$obj = new stdClass();
if($result){
    $obj->type = "success";
    $obj->msg = "上传成功到云中";
    $obj->url = $result;
}else{
    $obj->type = "fail";
    $obj->msg = "上传失败";
}
echo json_encode($obj);
exit;

 

 

父类中寻找后代元素:

42.$("#usersInfoForm").find("button[type='submit']").bind('click', function(){code...}

 

  1. 排除干扰CSS, 应该注释一些css,找到精确文件

44.unlink($savePath); //删除图片
rmdir($oldSavePath); //删除前一天的目录

45. shell上的定时任务,每分钟执行一次下面的PHP文件, 分时日月周

*/1 * * * * php /wwwroot/367edu.com/services/view_task.php

 

46.$.post('/ucenter.php?a=common.issentImg',{imgUrl:img}, function(data){
    var rs = jQuery.parseJSON(data);
    if(rs.type=='error'){
        bootbox.alert(rs.msg);
    }else{
        $("#block").show();
    }
});

 

  1. 根据某个分组的和的大小排序:   order by field(sgi.teacher_id,16696,17181,15429,17202)

select sgi.rtime,sgi.integral,sgi.content,st.name,stg.title from sc_teacher_growing_record sgi join sc_teacher_growing_type stg on sgi.type_id=stg.id  join sc_teacher st on st.id=sgi.teacher_id where sgi.users_id=9126 and sgi.is_del=0 and sgi.status=1 and sgi.teacher_id in (16696,17181,15429,17202)  order by field(sgi.teacher_id,16696,17181,15429,17202), st.name asc,sgi.status asc,sgi.create_date desc;

 

48.trigger("click")自动执行一次点击事件

$("#QR_code").on("click",function () {
    document.getElementById('vcode').src = '/?a=code&t='+Math.random();
})
$("#QR_code").trigger("click");//自动执行一次点击事件,即刷新该验证码

 

 

49

如果$_POST没有打印出值,肯定是名字相同造成的.微工具中的表单项不能使用重名的text.

50.新建文件夹,点击右键SVN导出.填地址和账号.

51. 给下拉选框设定高度的方法:

' +
        ''
})
page += '

'+
    '
    '+
            suc.page_htmls+
            '
'+
    '
';

$("tbody").html(html);
$('.pager-class').html(page);

  1. Ajax select下拉框的请求:

$.ajax({
    type:'post',
    url:'edu.php?a=score.comment.ajax_change_grade',
    data:{h_grade:h_grade},
    success:function (result) {
        var list = jQuery.parseJSON(result);
        $('.h_class').html('');
        for(var i = 0; i < list.data.length; i++){
            $('.h_class').append("");
        }
        return false;
    }
})

 

  1. 在使用form表单的时候,清除actionmethod="post"这两个属性可以使用ajax来提交表单       必须处在之内

$('.saveInfo').click(function (e) {
    e.preventDefault();//阻止元素发生默认的行为。
// var data = new FormData($('.form_')[0]);
    var form = $('.form_').serializeArray();
    $.ajax({
      type:'post',
      url:'oa.php?a=admin.booking.info&action=update_config',
      data:form,
      success:function (result) {....}

})

  1. 文件上传获取文件的参数 :

 var formData = new FormData($( "#uploadForm" )[0]);

$("#file").change(function(){
    var formData = new FormData($( "#uploadForm" )[0]);

此方法是专用获取图片的方法


    console.log(formData);
    $.ajax({
        type:'post',
        url:'/oa.php?a=wap.wfxx_upload_file',
        data:formData,
        contentType: false,    // 注意这里应设为false
        processData: false,
        cache: false,
        success:function () {

   
        }

})

 

})

  1. 所有checkboxname属性都是category[],为什么要这样设置?这样设置是因为我们将所有checkbox复选框作为一个组,在php服务器端可以使用$_POST['category']来获取所有被选中的复选框的值。

  • php教程
  •   

  • java教程
  •   

  • mysql教程
  •   

  • html教程
  •  

    1. 获取access_token

      通过code获取access_token(在自己服务器端做)

    https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code

    $rs_data = http_request_json($url);//curl函数获取网址里面的内容,返回json字符串,使用json_decode函数转换
    $rs = json_decode($rs_data);

     

    模板消息获取access_token接口

    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->appid.'&secret='.$this->appsecret;

     $result = json_decode(file_get_contents($url));

    $access_token = $result->access_token;

     

    发送模板消息接口

    $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $Access_token;

    return $this->http_request_json($url, $msg);

    $msg = '{
                 "touser":"' . $openid . '",openid是发送消息的基础,发送给谁
                 "template_id":"'.$userTemplateInfo->wxmsg_id.'",模板id
                 "topcolor":"#E02510",顶部颜色
                 "url":"' . $url . '",   点击跳转地址
                 "data":{
                             "first":{
                                     "value":"设备报修",
                                     "color":"#333333"
                             },
                             "keyword1":{
                                     "value":"' . $vals->repair_ren . '",
                                     "color":"#333333"
                             },
                             "keyword2":{
                                     "value":"' . $vals->repair_xq . '",
                                     "color":"#333333"
                             },
                             "keyword3":{
                                     "value":"' . $vals->repair_lx . '",
                                     "color":"#333333"
                             },
                             "keyword4":{
                                     "value":"' . $vals->repair_dz . '",
                                     "color":"#333333"
                             },
                             "keyword5":{
                                     "value":"' .date('Y-m-d H:i',time()) . '",
                                     "color":"#333333"
                             },

                             "remark":{
                                     "value":"点击查看详情",
                                     "color":"#333333"
                             }
                     }
    }';

     

     

     

    这个地址可以获取如下信息:{

        "access_token":"ACCESS_TOKEN",  接口调用凭证

        "expires_in":7200, 接口调用凭证超时时间,单位(秒)

        "refresh_token":"REFRESH_TOKEN",用户刷新access_token

        "openid":"OPENID",  授权用户唯一标识

        "scope":"SCOPE", 用户授权的作用域,使用逗号(,)分隔

        "unionid":"o6_bmasdasdsad6_2sgVt7hMZOPfL"只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。

    }

     

    1. 联图网二维码接口:x 必须用UTF8编码格式,x内容出现 & 符号时,请用 %26 代替,
      换行符使用 %0A.   :x=http://baidu.com


     

    107.图片上传后台处理程序:

     


    $rs = new stdClass();
    //print_r($_FILES);

    if(!$_SESSION['jxht'][$__users_id__]['member_id']){
        $rs->type = 'error';
        $rs->msg = "操作错误,请重新刷新操作";
        echo json_encode($rs);
        exit;
    }


    set_time_limit(0);

    $fname=basename($_FILES['hml']['name']);
    $fsize = $_FILES['hml']['size'];
    $f=explode(".",$fname);


    if(count($f)<2){
        $rs->type = 'error';
        $rs->msg = "上传文件格式不正确!";
        echo json_encode($rs);
        exit;
    }
    $extname= strtolower($f[count($f)-1]);
    $ext = array('doc', 'docx', 'wps', 'wpt', 'ppt', 'pptx', 'xls', 'xlsx', 'et', 'ett', 'pdf', 'mp3', 'mp4', 'zip', 'rar', 'jpg', 'gif', 'png', 'jpeg', 'bmp'); // 允许文件
    if(!in_array($extname,$ext)){
        $rs->type = 'error';
        $rs->msg = "上传文件格式不正确!";
        echo json_encode($rs);
        exit;
    }
    if(in_array($extname,array("tpl","html","js","php","php3"))){
        $rs->type = 'error';
        $rs->msg = "上传文件格式不正确!";
        echo json_encode($rs);
        exit;
    }

    $rand = rand(1000, 9999);
    $fileName= substr(time(),5).$rand.".$extname";


    $uploadPath = $_SITE_PATH_ . "upload/".$__users_id__."/oa/";
    if(!is_dir($uploadPath)){
        mkdir($uploadPath, 0777, true);
    }

    $folder = date("ymd");
    if(!file_exists($uploadPath.$folder."/0.hide")){
        mkdir($uploadPath.$folder, 0777, true);
        file_put_contents($uploadPath.$folder."/0.hide", "");
    }
    $src=$folder."/$fileName";
    $savePath=$uploadPath.$src;

    $test = $uploadPath.$folder;

    if (!move_uploaded_file($_FILES['hml']['tmp_name'], $savePath)) {
        $rs->type = 'error';
        $rs->msg = "文件上传出现错误";
        echo json_encode($rs);
        exit;
    }

    $data = new stdClass;
    $data->download_url = "/sites/oa/upload/".$__users_id__."/oa/".$src;

    $rs->type = 'succeed';
    $rs->msg = "添加成功";
    $rs->data = $data;
    echo json_encode($rs);
    exit;

    107表单的提交获取值:

        

        

        bike

        car

        Male

        Female

        提交">

    打印的值:Array

    (

        [input_name] =fsdfsdf

        [color] =0

        [vehicle] =Array

            (

                [0] =bike

                [1] =car

            )

     

        [sex] =female

    )

     

     

     

     

     

    转载于:https://www.cnblogs.com/hml-blog-com/p/10096785.html

    你可能感兴趣的:(php,数据库,javascript)