PHP,mysql,Linux,CI框架学习总结

PHP,mysql,CI框架学习总结


PHP标记

1.Xml风格<?php ?>
2.简短风格  <?  ?>  需在php.ini中开启short_open_tag
3.asp风格   <%  %>  需在php.ini中开启asp.tags
4.脚本风格  <script language="php"></script>

PHP注释

1.单行注释://,#
2.多行注释:/* */

变量申明

1.以$为开头
2.大小写敏感

静态变量Eample:

class test
    {
        public static $constr="这是一个静态变量";
    }
    echo test::$constr;

全局变量

1.$_GET
2.$_POST
3.$_REQUEST
4.$_FILES
5.$_SESSION             使用前,需session_start();
6.$_COOKIE
7.$_SERVER
8.$_ENV
9.$_GOLBALS

基本函数

    1.var_dump()    //查看数据类型
    2.isset()       //判断变量是否存在
    3.empty()       //判断变量是否为空
    4.is_string(),is_numeric()··    //判断相关数据类型
    5.unset()       //销毁变量
    6.define()      //定义相关常量
    7.date("Y-m-d H:i:s")   //获取系统时间
    8.set_default_timezone_set("Etc/GMT-8");    //设置时间为东八区
    9.die(),exit()          //终止运行
    10.error_log(mysqli_connect_error(),3,"1.txt");         //记录系统日志

基本字符串函数

    1.字符串格式化
        1).ltrim(),rtrim(),trim()   //删除空格
        2).str_pad()                //填充字符串
        3).string_format()          //格式化字符串[可用于数字格式化]
        4).ucfirst(),lcfirst()      //首字母大小写
        5).ucwords()                //单词首字母大写[以逗号隔开后,不执行]
        6).strtoupper(),strtolower()    //转换大小写
        7).strlen(),mb_strlen()        //字符长度,前为英文,后卫中文,utf-8下,一个汉字占三个字符
        8).strrev()                 //字符串反转[中文下乱码]
        9).substr_count(),mb_substr_count()     //统计词频
        10).md5()                   //md5加密
    2.字符串比较
        1).strcmp(),strcasecmp()    //比较,后者区分大小写
    3.字符串分割,截取
        1).implode()            //将数组拼接为字符串
        2).explode()            //将字符串分割成数组,根据参数字符
        3)str_split()           //将字符串分割成数组,根据长度
        4)substr(),mb_substr()  //截取字符串,后者为中文
        5).str_replace()        //替换子串
        6).strstr(),stristr()             //根据字符参数,截取字符串
        7).strpos(),strrpos()   //返回字符串第一次出现的位置
    4.其他
        1.json_encode($str,JSON_UNESCAPED_UNICODE)         1.对字符串进行json编码,支持中文,JSON_UNESCAPED_UNICODE参数使用版本PHP5.4+
        2.json_decode();        //对json数据进行解码

数组函数

    1.键值操作
        1).array_values()       //获取值array()
        2).array_keys()         //获取键array()
        3).array_filp()          //交换键值
        4).array_reverse()      //反转字符
    2.指针操作:
        1).reset()                     //重置指针
        2).next(),prev()                 //进前,退后指针
        3).current()                   //当前指针
        4).end()                       //最后指针
        5).key()                       //当前键
    3.查询操作
        1).in_array()                   //是否存在
        2).array_values(),array_keys()
        3).array_key_exists()
    4.统计
        1).array_count_values()     //统计数组中,元素出现的频率
        2).array_unique()           //数组去重
        3)count()                   //数组长度
    5)排序
        1).sort(),rsort()           //按值排序,丢弃原有键
        2).ksort(),krsort()         //按键排序
        3).asort(),arsort()         //按值排序,不丢弃原有键
    6).操作
        1).array_slice()             //截取数组
        2).array_splice()           //数组替换
        3).array_combine(),array_megre()    //数组合并
        4).array_intersect()            //数组交集
        5)array_diff()                 //取数组差集,以某一参数为基准
    7).数组回调
        1).array_filter()               //使用回调函数过滤数组
        2).array_walk()             //使用回调函数,操作数组,不改变数组值
        3).array_map()              //使用回调函数,操作数组,改变数组值

**文件操作

1.打开文件:    $logfile=fopen("1.txt",'a');
2.写入文件:    fwrite($logfile,'logmes');      //写入文件时,头不能写入"\r\n"
3.关闭文件:    fclose($logfile);
4.判断文件存在:    file_exits()
5.确定文件大小:    filesize();
6.删除文件:         unlink();

附:fopen列表
此处输入图片的描述
数据库操作

数据库操作类:
<?php
    class db_oper
    {
        private $hostname="127.0.0.1";
        private $dbname="root";
        private $dbpassword="52ebook";
        private $dbdatabase="test";
        private $conn;
        function construct()
        {
            $this->conn=new mysqli($this->hostname,$this->dbname,$this->dbpassword,$this->dbdatabase);
            if(mysqli_connect_errno())
            {
                echo mysqli_connect_error();
                die;
            }
            $this->conn->set_chartset("utf8");
        }
        function exec($sql)
        {
            $this->conn->query($sql);
            return $this->conn->affected_rows;
        }
        function seldb($sql)
        {
            $result=$this->conn->query($sql);
            return $result->fetch_all(MYSQLI_ASSOC);
        }
        function getid($sql)
        {
            $this->conn->query($sql);
            return $this->conn->insert_id;
        }
        function destruct()
        {
            $this->close();
        }
    }
?>

PHP服务器部署

    1.不显示程序错误信息:
        修改php.ini文件,修改参数为:display_errors=off,error_reporting=E_All & ~E_NOTICE
        重启apache服务器[Windows平台测试通过]
    注意点:1.确认修改的phi.ini文件为apache服务器所使用的文件,可用phpinfo确认文件位置
    2.设置文件上传:
        file_uploads=on
        upload_max_filesize=8M
        post_max_size=8M
        upload_tmp_dir      文件上传临时目录
    注意点:post的值一定要大于upload的值
    3.设置默认时区:
    date.timezone=Etc/GMT-8
    4.日志信息
        error_log       日志文件位置
        log_errors      是否启用日志
        log_errors_max_length   日志信息的最大长度,0表示无限长度
    附录:常见的日志级别

此处输入图片的描述

    5.重启apache命令:
        httpd -k restart    [windows平台,执行前先进入apache文件夹]
        service httpd restart   [Linux平台]
    6.htaccess部署:
    打开apache下的httpd.conf配置文件,进行参数修改
        1.    Options FollowSymLinks 
              AllowOverride None 
              改为:
              Options FollowSymLinks 
              AllowOverride All 
        2.开启rewrite_module modules,即
            去掉LoadModule rewrite_module modules/mod_rewrite.so注释
        3.重启apache服务器
        4.htaccess参数
        RewriteEngine on      
        <IfModule authz_core_module>
        Require all denied
        </IfModule>
        <IfModule !authz_core_module>
             Deny from all
        </IfModule>
        <IfModule mod_rewrite.c>
            RewriteEngine on 
            RewriteCond $1 !^(index\.php|images|js|img|css|robots\.txt) #在这里写要排除的资源等 
            RewriteRule ^(.*)$ index.php/$1 [L] 
        </IfModule>
    7.web服务器为IIS时,需安装ISAPI_Rewrite

Linux平台下LAMP环境安装实施

以CentOS6.5安装LAMP:
PHP:5.3.3
Mysql:5.1.71
Apache:Apache 2.2.15

以CentOS6.5 Yum安装LAMP:
PHP:5.3.3[CentOS6.5]
Mysql:5.1.71[Yum]
Apache:Apache 2.2.15[CentOS6.5]

查找某个文件:find / -name tnsnames.ora
机器名:hostname

环境检查:
libxml2-2.7.4.tar.gz[PHP]
解包:
tar   jxvf   linux-2-4-2.tar.bz2

查看yum软件版本:
yum list php
yum list mysql
yum list httpd

查看rpm包版本:
rpm -qa|grep 
httpd/mysql/php

查询Linux版本:cat /etc/redhat-release   Redhat/CentOS版本

1.关闭防火墙:
/etc/init.d/iptables stop[临时]
chkconfig --level 35 iptables off[永久,重启]

防火墙状态:service iptables status
selinux状态:sestatus
关闭selinux:
vi /etc/selinux/config
SELINUX=disabled
重启

2.安装Apache
1.yum install httpd 
2./etc/init.d/httpd restart 
3.chkconfig httpd on

状态查询:service httpd status
查询apache版本:httpd -v
配置文件:/etc/httpd/conf/httpd.conf
默认路径:/var/www/html/,默认首页:index.html
默认配置文件路径:/etc/httpd/conf/httpd.conf
查询apache安装路径:whereis httpd

3.安装mysql
1.yum install mysql mysql-server
2./etc/init.d/mysql start
3.chkconfig mysqld on
4.mysql_secure_installation[设置mysql密码]
5./etc/init.d/mysqld restart

状态查询:service mysqld status
查询mysql版本:status
               select version();
查询安装路径:select @@basedir as basePath from dual;

卸载mysql:
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
查看是否还有mysql软件:
rpm -qa|grep mysql
有的话继续删除

4.安装PHP
1.yum install php
2./etc/init.d/httpd restart
3. yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt[PHP组件]
4./etc/init.d/httpd restart   
5./etc/init.d/mysqld restart 
附录:
1.以yum方式安装PHP5.5.24
    1).yum remove php  php-bcmath php-cli php-common  php-devel php-fpm    php-gd php-imap  php-ldap php-mbstring php-mcrypt php-mysql   php-odbc   php-pdo   php-pear  php-pecl-igbinary  php-xml php-xmlrpc
    2).rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
    3).yum install php55w  php55w-bcmath php55w-cli php55w-common  php55w-devel php55w-fpm    php55w-gd php55w-imap  php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql   php55w-odbc   php55w-pdo   php55w-pear  php55w-pecl-igbinary  php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache
    4).service httpd restart

查询php版本:
php -v

测试:
在/var/www/html中修改1.php信息
phpinfo();
在phpinfo()中显示php.ini文件路径,在"etc/php.ini"下[CentOS]

设置:
1.Apache设置
vi /etc/httpd/conf/httpd.conf
1. ServerTokens OS  修改为:  ServerTokens Prod (在出现错误页的时候不显示服务器操作系统的名称)
2.ServerSignature On        修改为:     ServerSignature Off  (在错误页中不显示Apache的版本) 
3.Options Indexes FollowSymLinks     修改为:     Options Includes ExecCGI FollowSymLinks 
 (允许服务器执行CGI及SSI,禁止列出目录) 
 附录:
 Apache虚拟目录配置:
 1.vi /etc/httpd/conf/httpd.conf
 Alias /herod "/var/www/herod"
    <Directory "/var/www/herod">
               Options Indexes MultiViews
               Order allow,deny
               Allow from all
   </Directory>
    #cd /var/www
    #mkdir herod
    #echo "欢迎访问herod的虚拟目录">index.html
2.service restart httpd
 Apache虚拟主机配置:
 1.vi /etc/httpd/conf/httpd.conf
 添加:
 ServerName 58.130.17.168    
 NameVirtualHost 58.130.17.168     
<VirtualHost 58.130.17.168>    
        ServerName domain1.com    
        DocumentRoot /var/www/domain1.com    
        <Directory "/var/www/domain1.com">    
            Options Indexes FollowSymLinks    
            AllowOverride None    
            Order allow,deny    
            Allow from all    
        </Directory>    
</VirtualHost>    
<VirtualHost 58.130.17.168>    
        ServerName domain2.com    
        DocumentRoot /var/www/domain2.com    
        <Directory "/var/www/domain2.com">    
            Options Indexes FollowSymLinks    
            AllowOverride None    
            Order allow,deny    
            Allow from all    
        </Directory>    
</VirtualHost>    
然后在/var/www/domain1.com和/var/www/domain2.com下创建不同的index.html文件:    
echo "domain1">/var/www/domain1.com/index.html    
echo "domain2">/var/www/domain2.com/index.html
2.vi /etc/hosts
添加:
58.130.17.168   test1.com
58.130.17.168   test2.com

Nginx yum安装:
    1).rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    2).yum install nginx
    3).service nginx start
Nginx默认配置文件路径:
vi /etc/nginx/conf.d/default.conf   [ps -ef|grep nginx]

Nginx,php配置:
        1).安装php-fpm yum install php-fpm
        2).启动php-fpm /etc/rc.d/init.d/php-fpm start
        3).自动启动 chkconfig php-fpm on
新建用户,组:
        groupadd gx
        useradd -g gx gx
配置php-fpm:
        cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak
        vi /etc/php-fpm.d/www.conf
        user=gx
        group=gx
配置nginx支持php
        cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
        vi /etc/nginx/nginx.conf
        user gx 
        cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak
        vi /etc/nginx/conf.d/default.conf
        index index.php index.html index.htl
        location ~ \.php$ {
       #root           html;
      fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME          /usr/share/nginx/html$fastcgi_script_name;
       include        fastcgi_params;
   }
重启服务   
            /etc/rc.d/init.d/php-fpm restart
            service nginx restart
nginx版本:nginx -v

配置nginx之处CI rewrite:
vi /etc/nginx/con.d/default.conf
server {
        listen       80;
        server_name  192.168.1.125;                 //一定是IP或域名,不能用localhost[Linux下,localhost≠127.0.0.1]
        charset utf8;               //设置编码
        root  /usr/share/nginx/html;        //网站根目录

        location / {
            index index.php index.html;
     }   
        
         location ~ \.php($|/) {
            
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index  index.php;
           fastcgi_split_path_info ^(.+\.php)(.*)$;
           fastcgi_param   PATH_INFO $fastcgi_path_info;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param    PATH_TRANSLATED   $document_root$fastcgi_path_info;
            include fastcgi_params;
        }   

        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?$1 last;         //关系url重写
            break;
        }   
        access_log  /logs/access.log;                   //设置日志路径
        error_log  /logs/error.log;
    }

注意点:调试CI时,如输入CI日志,在配置log_path时,需对相应路径进行赋权 
        chown -R gx /logs
        chmod 777 /logs
        
LNMP安装:[http://lnmp.org/]
按官方步骤下载安装[40min]。
查看mysql服务:service mysql status
连接Mysql:mysql -h127.0.0.1 -uroot -p  [注意关闭防火墙]
默认安装路径为:/usr/local/nginx|mysql|php

Nginx配置虚拟主机:
修改nginx.conf配置文件,添加[未验证]:

此处输入图片的描述

Nginx配置虚拟主机:
location /test/
            {
                root /home/wwwroot/default/;
                index index.php;
            }
Linux监控软件,Cacti安装
:    1.安装rrdtool  
1.rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
2.yum install rrdtool -y

2.安装net-snmp
1.yum install net-snmp net-snmp-libs net-snmp-utils
2.配置net-snmp
在/etc/snmp/snmpd.conf中修改:
view    systemview    included   .1.3.6.1.2.1.1
为:
view    systemview    included   .1.3.6.1.2.1
3、测试net-snmp
# service snmpd start
# snmpwalk -v 1 -c public localhost .1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux cronos 2.4.28 #2 SMP ven jan 14 14:12:01 CET 2005 i686

3.安装cacti
1、下载cacti
cd /tmp
wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
tar xzf cacti-0.8.8b.tar.gz
mv cacti-0.8.8b /var/www/html/cacti
cd /var/www/html/cacti
2、创建数据库
mysqladmin --user=root -p create cacti
3、导入数据库
mysql -uroot -p cacti < cacti.sql
4、创建数据库用户
shell> mysql -uroot -p mysql
**mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';**
mysql> flush privileges;
5、配置include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactipassword";
 
/* load up old style plugins here */
$plugins = array();
//$plugins[] = 'thold';
 
/*
   Edit this to point to the default URL of your Cacti install
   ex: if your cacti install as at http://serverip/cacti/ this
   would be set to /cacti/
*/
$url_path = "/cacti/";
 
/* Default session name - Session name must contain alpha characters */
#$cacti_session_name = "Cacti";
6、设置目录权限
useradd cactiuser
chown -R cactiuser rra/ log/
7、配置计划任务
echo "*/5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1">>/etc/crontab
service crond restart
service httpd restart
8、完成cacti的安装
1) 在浏览器中输入:http://www.yourdomain.com/cacti/
默认用户名:admin 密码:admin
2) 更改密码
3)设置cacti用到的命令路径

配置:
https://www.centos.bz/2012/06/cacti-monitor-traffic/
1.登录cacti,点击“Devices”,然后点击"Add"创建设备
2.然后输入Description,Hostname,Host Template选择“Generic SNMP-enabled Host”,SNMP Version一般选择“Version 1”(当然得根据你具体的snmp如何配置)。完成后点击"create"创建设备
3.接着在顶部点击“Create Graphs for this Host”创建图表
4.在“SNMP - Interface Statistics”下面会显示你的网卡,选择其中一个监控即可,我们这里选"eth0",之后单击“create”。
5.现在已经成功创建图表,我们点击左侧的“Graph Management”查看图表列表,此时已经可以看到刚才创建的图表,点击相应的图表标题进去查看。
6.现在可能图表还没开始生成,最多等待5分钟,5分钟后图表是创建了,但图表没有数据,需要等待一段时间程序收集数据

mysql小结

    语句备查:
        1.登录  mysql -h127.0.0.7 -uroot -p
        2.当前时间  select now();
        3.显示版本  select version();
        4.显示所有库,表    show databases;show tables;
        5.文件路径      show variables like 'datadir%'
        6.显示表结构    desc tablename;
        7.查看当前库    select database();
        8.联查,判断    
        select stu_table.sid as '学号',sname as '姓名',`subject` as '科目',score as '成绩',case sex when 0 then '女' when 1 then '男' end as '性别' from score_table left join stu_table on score_table.sid=stu_table.sid
        9.空判断
        select sname,class,IFNULL(score,60)score from stu_table left join score_table on score_table.sid=stu_table.sid
        10.分页,查询
        select * from food where title like '新%' order by title asc limit 0,3
        11.时间格式化
        select protitle,protent,date_format(protime,'%Y-%m-%d %H:%i')as protime,case prostatus when 0 then '未解决' when 1 then '已解决' end as prostatus from pro_tab;
        12.判断更新
        update pro_tab set prostatus=if(1=prostatus,0,1) where proid='1';
        13.批量插入
        insert into food(title,pic) values 
            ('aa','aa'),
            ('bb','bb'),
            ('cc','cc')
        14.修改表数据设置默认值
        alter table food change pic pic varchar(1000) default '没图片';
        15.mysql开启远程连接
        grant all PRIVILEGES on *.* to ted@'192.168.1.109' identified by '123456';
        flush privileges;
        enterprise为数据库名,ted为用户账号,123456为用户密码。
        15.Linux下,mysql数据库显示中文乱码,修改编码:
            show variables like 'character_%';  
            set character_set_server=utf8;
        16.mysql库目录:/var/lib/mysql      [CentOS6.5平台,常规]
        17.备份[Linux]:
            1).cd /var/lib/mysql
            2).mysqldump -u root -p databasename>databasename.sql
        18.还原[Linux]
            1).cd /var/lib/mysql
            2).mysql -u root -p databasename<database.sql
            注意点:在还原之前先确认是否存在数据库,如不存在,则先建库
        19.mysql导入脚本:
        source /var/lib/enterprise.sql
        20.mysql自动备份脚本[Linux]:
            1.
            #! /bin/sh
            #File: /mysqlback.sh
            #database info:
            dataname="enterprise"
            datauser="root"
            datapass="52ebook"

            #Others vars
            bin_dir="/usr/bin"
            back_dir="/back"
            DATE=`date +%F`

            #Todo
            $bin_dir/mysqldump --opt -u$datauser -p$datapass $dataname|gzip>$back_dir/db_$DATE.gz
            2.给脚本赋权
            chomd 777 /mysqlback.sh
            2.vi /etc/crontab
            01 5 * * * root /home/mysql/backup.sh
            或在crontab -e里添加
            备注:检查cron服务状态:
            1.service crond status
            2.crond日志:/var/log/cron            

此处输入图片的描述

21.两表批量更新:
update student inner join user_tab ON student.`准考证号`=user_tab.card_num
set student.`身份证号`=user_tab.indentity_code;
22.查询字段名
select column_name from information_schema.`COLUMNS` where TABLE_NAME='student';
23.子查询
select * from user_tab where card_num in (select `准考证号` from student where `姓名`='陈海')
24.联合查询
select * from user_tab,student where user_tab.card_num=student.`准考证号`;
select * from student inner JOIN user_tab on student.`准考证号`=user_tab.card_num;
25.条件更新
update student set `备注`=case `准考证号` when '18625964' then '1'  when '13425161' then '2' when '10725661' then '3' end ;
26.多条件排序
SELECT * from student where `身份证号` is null order by `备注` desc,`准考证号` asc;
27.Full join
select * from student left JOIN user_tab on student.`准考证号`=user_tab.card_num 
UNION
select * from student right JOIN user_tab on student.`准考证号`=user_tab.card_num ;
28.分数筛选,其中分数为字符类型
SELECT * from student where `分数` BETWEEN 60 and 100 order by `分数`+0 asc
29.转换,convert(field,datatype),cast(field,datatype)
30.移动表从一个库到另一个库 rename table `work`.temp1 to b_work.temp1;
31.批量字段插入新表insert into `stu`(id,`name`,gender) select id,`name`,gender from exam_doctors;
支持类型:
二进制,同带binary前缀的效果 : BINARY    
字符型,可带参数 : CHAR()     
日期 : DATE     
时间: TIME     
日期时间型 : DATETIME     
浮点数 : DECIMAL      
整数 : SIGNED     
无符号整数 : UNSIGNED 
30.随机排序
SELECT *,convert(`准考证号`,char) as `考号` from student where `分数` BETWEEN 60 and 100 order by rand() asc
31.联合查询
select concat(`姓名`,'-',`身份证号`) as `人员信息` from student;
32.追加时间
select date_add(now(),INTERVAL 100 day)
33.统计及格人数
select `class`,sum(case when score>=60 then 1 else 0 end),sum(case when score>=60 then 0 else 1 end) from student group by 1
34.跨库查询
select * from `work`.exam_doctors union select * from b_work.exam_doctors;
35.分组,排序
select t_jeff.* from (select vinnumber,max(channelid) as maxid from t_jeff  GROUP BY vinnumber) m
INNER JOIN t_jeff  on t_jeff.vinnumber=m.VINNumber order by m.maxid desc,t_jeff.vinnumber,t_jeff.channelid desc;
36.获取当前时间:
select CURRENT_TIMESTAMP();
select CURRENT_DATE();
select CURRENT_TIME();
select now();
37.格式化时间:
select DATE_FORMAT(now(),'%y-%m-%d') as time
相关参数:
%S, %s 两位数字形式的秒( 00,01, . . ., 59)
%i 两位数字形式的分( 00,01, . . ., 59)
%H 两位数字形式的小时,24 小时(00,01, . . ., 23)
%h, %I 两位数字形式的小时,12 小时(01,02, . . ., 12)
%k 数字形式的小时,24 小时(0,1, . . ., 23)
%l 数字形式的小时,12 小时(1, 2, . . ., 12)
%T 24 小时的时间形式(h h : m m : s s)
%r 12 小时的时间形式(hh:mm:ss AM 或hh:mm:ss PM)
%p AM 或P M
%W 一周中每一天的名称( S u n d a y, Monday, . . ., Saturday)
%a 一周中每一天名称的缩写( Sun, Mon, . . ., Sat)
%d 两位数字表示月中的天数( 00, 01, . . ., 31)
%e 数字形式表示月中的天数( 1, 2, . . ., 31)
%D 英文后缀表示月中的天数( 1st, 2nd, 3rd, . . .)
%w 以数字形式表示周中的天数( 0 = S u n d a y, 1=Monday, . . ., 6=Saturday)
%j 以三位数字表示年中的天数( 001, 002, . . ., 366)
% U 周(0, 1, 52),其中Sunday 为周中的第一天
%u 周(0, 1, 52),其中Monday 为周中的第一天
%M 月名(J a n u a r y, February, . . ., December)
%b 缩写的月名( J a n u a r y, February, . . ., December)
%m 两位数字表示的月份( 01, 02, . . ., 12)
%c 数字表示的月份( 1, 2, . . ., 12)
%Y 四位数字表示的年份
%y 两位数字表示的年份
%% 直接值“%”
38.多表查询
select * from (select exam_doctors.id,exam_doctors.`name`,exam_doctors.indentity_code,exam_fetch.card_num from exam_doctors LEFT JOIN  exam_fetch on exam_doctors.id=exam_fetch.id) m
RIGHT JOIN student on student.`准考证号`=m.card_num where `身份证号` is null
39.截断表
truncate table tablename
40.查询增强
select `所在地区`,avg(`分数`) as `平均分`,count(`身份证号`) as `人数` from (
select student.* from (select exam_doctors.id,exam_doctors.`name`,exam_doctors.indentity_code,exam_fetch.card_num from exam_doctors LEFT JOIN  exam_fetch on exam_doctors.id=exam_fetch.id) m
RIGHT JOIN student on student.`准考证号`=m.card_num) t GROUP BY `所在地区`;
41.字符长度
select * from student where LENGTH(trim(`姓名`))<>6 and LENGTH(trim(`姓名`))<>9;
42.group by,having
select `所在地区`,avg(`分数`) as `平均分`,count(`身份证号`) as `人数` from (
select student.* from (select exam_doctors.id,exam_doctors.`name`,exam_doctors.indentity_code,exam_fetch.card_num from exam_doctors LEFT JOIN  exam_fetch on exam_doctors.id=exam_fetch.id) m
RIGHT JOIN student on student.`准考证号`=m.card_num) t GROUP BY `所在地区` HAVING `人数`>300;
43.判断与统计
select 所在地区,case when `分数`>=60 then '及格' when `分数`<60 then '不及格' end as `成绩`,count(`身份证号`) as 人数 from student group by `所在地区`,`成绩`;
44.子查询
select card_num from exam_fetch where card_num not in (select `准考证号` from student);
45.整表插入
insert into student2 SELECT * from student;
46.Linux下,mysql 查询乱码:
查询前,先执行:set NAMES 'utf8'

CI框架学习总结

首页配置:
    1.$config['base_url']='http://127.0.0.1/CodeIgniter';   [config.php]
    2.$config['index_page']='index.php';                    [config.php]
    3.$route['default_controller']='Contacts';              [routes.php]
数据库配置:database.php
连接数据库:
    1.$autoload['libraries']=array('database');           [autoload.php]
    2.$this->load->database();
全局变量:
    define('SysName','SysName');                            [index.php]
错误级别定义:
1.error_reporting()设置             [index.php]
2.log_path设置日志文件路径,按日期记录,log-time,一天一个文件
错误日志记录:
$config['log_threshold']=0控制          [config.php]
定义错误信息:
修改404错误信息:
修改function show_404中的显示信息       [system/core/Exceptions.php]
错误页面:位于views/errors文件夹下
3.CI大小写的问题[linux下必须严格遵守此规则]:
Control文件为首字母大写,Control中调用的module方法为小写
Views文件为小写
Module文件为首字母为大写

Linux常用命令

1.重启网卡:service network restart
2.执行sh脚本:sh mysqlback.sh
3.查看日志:tail -f sys.log
4.更正系统时间:ntpdate time.nist.gov
5.开机自动矫正时间:chkconfig ntpd on
6.重启:reboot
7.版本信息:cat /etc/issue  [centos]

微信企业平台开发
: 基础概念:
功能:
1).公告通知
2).知识管理
3).企业文化建设
4).手机企业通讯录
主动调用:
1).https协议
2).json数据格式
3).UTF编码
4).访问域
5)数据不加密
回调模式:
1URL
2.Token
3.EncodingAESKey
经验与技巧

1.Linux下,默认不开启php.ini的error_log,如需调试需开启 [CentOS6.5]
2.PHP版本不同,对mysqli的支持不同,某些方法不能用       [CentOS6.5]
3.在Linux下,htaccess文件为隐藏文件
4.Linux脚本调试
    输出相关路径:echo $bin_dir> /back/1.log
5.虚拟机下(宿主机ip自动获取),centos可上内网不能上外网,则:
cd /etc/sysconfig/network-scripts/
vi route-ech0[新建]
via 192.168.1.1
保存,service restart network,而后选取DHCP自动连接即可上外网
6.Linux防火墙开放端口:
1.vi /etc/sysconfig/iptables
2.添加条目:
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
端口:80为web端口,3306为mysql端口
7.CentOS设置静态IP:

    1.vi /etc/sysconfig/network-scripts/ifcfg-eth0
    
        DEVICE=eth0                 //指出设备名称
        BOOTPROT=static             //启动类型 dhcp|static
        BROADCAST=192.168.1.203     //广播地址
        HWADDR=00:06:5B:FE:DF:7C    //硬件Mac地址
        IPADDR=192.168.0.2          //IP地址
        NETMASK=255.255.255.0       //子网掩码
        NETWORK=192.168.0.0         //网络地址
        GATEWAY=192.168.0.1         //网关地址
        ONBOOT=yes                  //是否启动应用
        TYPE=Ethernet               //网络类型

 2.service network restart

问题备查
: 1.Linux下,Another MySQL daemon already running with the same unix socket

    service mysqld stop
    mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
    service mysqld start

2.Linux下,查看端口占用

     netstat -tunlp |grep 22
     lsof -i:端口号

3.Linux下,查看ssh服务

    service sshd status
    配置文件:vi /etc/ssh/sshd_config

4.Another app is currently holding the yum lock,

    rm -rf /var/run/yum.pid

5.httpd已死,但是subsys被锁

  1.cd /var/lock/subsys
  2.rm httpd
  3.service httpd restart
    

转载于:https://www.cnblogs.com/fangbaiyi/p/4569674.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux上使用C语言编写MySQL程序需要进行一些准备工作。首先,需要安装MySQL的C/C++ API和相关的依赖项,可以使用以下命令进行安装:sudo apt-get install mysql-server libmysql-dev。然后,将MySQL的头文件复制到C/C的头文件目录,以便可以调用这些头文件。可以使用以下命令将头文件复制到相应的目录:sudo cp /usr/lib/mysql/* /usr/lib/。接下来,可以使用mysql_query函数执行MySQL命令。该函数的参数应使用C风格字符串,例如mysql_query(&mysql, "select * from info")。最后,可以使用mysql_store_result函数来存储执行结果。请注意,以上代码示例是用C++语言编写的,因此需要将字符串转换为C风格字符串(使用.c_str()方法)。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Linux下 C++ 操作 MySQL](https://blog.csdn.net/Mikchy/article/details/106697826)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [linux下使用c++操作mysql](https://blog.csdn.net/liushall/article/details/81144963)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值