Home > Backend Development > PHP Tutorial > my php & mysql FAQ

my php & mysql FAQ

WBOY
Release: 2016-06-23 14:34:54
Original
1171 people have browsed it

php中文字符串长度及定长截取问题使用str_len("中国") 结果为6,php系统默认一个中文字符长度为3,可改用mb_strlen函数获得长度,mb_substr函数截取字符

mb_strlen($str, "utf-8"); //1汉字为1字符
mb_strlen($str, "gb2312"); //系统会认为1汉字为2字符
mb_strlen($str); //如果没有添加,系统会认为1汉字为3字符

int mb_strlen ( string str [, string encoding] )

string mb_substr ( string str, int start [, int length [, string encoding]] ) 判断php变量是否定义,是否为空

if($keyword): 这样的语句如果在controller里没有set 到页面上判断语句会出错,改用表达式 isset($keyword)

表达式 gettype() empty() is_null() isset() boolean : if($x)
$x = ""; string TRUE FALSE TRUE FALSE
$x = null; NULL TRUE TRUE FALSE FALSE
var $x; NULL TRUE TRUE FALSE FALSE
$x is undefined NULL TRUE TRUE FALSE FALSE
$x = array(); array TRUE FALSE TRUE FALSE
$x = false; boolean TRUE FALSE TRUE FALSE
$x = true; boolean FALSE FALSE TRUE TRUE
$x = 1; integer FALSE FALSE TRUE TRUE
$x = 42; integer FALSE FALSE TRUE TRUE
$x = 0; integer TRUE FALSE TRUE FALSE 获取request多值参数

类似java的request.getParameterValues() (居然刚知道这个方法,==!)

页面form中 
后台处理请求

$kword=$_POST['kword'];

cakePHP对应方法为

$kword=$this->params['form']['kword'];

使用时按照设置的顺序$kword[index] index: 0-n php solr client api 取doc字段出现index not defined 错误解决方法:

solr文档可能某些字段不全,当取多个文档显示时,如果有的字段没有定义值会出现index not defined 错误

修改solr client api的Document文件
public function __get($key) {
//key不存在则返回空 避免出现index not defined 错误 shen guanpu 2010年7月15日13:51:52
return array_key_exists($key,$this->_fields)?$this->_fields[$key]:"";
//return $this->_fields[$key]; 原代码} Install CakePHP in a Subdirectory Via an Apache Alias
httpd.conf

In httpd.conf, add the following line:Alias /directory_name /absolute/path/to/install/directory/app/webroot
.htaccess

In app/webroot/.htaccess, add the following line:RewriteBase /directory_name
Your .htaccess file should now appear as such:


RewriteEngine On
RewriteBase /directory_name
RewriteCond % REQUEST_FILENAME !-d
RewriteCond % REQUEST_FILENAME !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

index.php

Finally, in app/webroot/index.php, at line 63, right below where it says not to edit below this line, change it to: define('WEBROOT_DIR', 'directory_name');
出处http://www.chriscassell.net/log/2006/07/27/how_to_install_.html mysql 远程访问设置

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES; PHP 闭合标签

PHP闭合标签“?>”在PHP中对PHP的分析器是可选的。 但是,如果使用闭合标签,任何由开发者,用户,或者FTP应用程序插入闭合标签后面的空格都有可能会引起多余的输出、php错误、之后的输出无法显示、空白页。因此,所有的php文件应该省略这个php闭合标签,并插入一段注释来标明这是文件的底部并定位这个文件在这个应用的相对路径。这样有利于你确定这个文件已经结束而不是被删节的。

INCORRECT:

CORRECT:
/* End of file myfile.php // Location: ./system/modules/mymodule/myfile.php */ php判断数字

bool is_numeric ( mixed var ) mysql IGNORE_SPACE mode
写concat函数时出现 concat dose not exist错误

更改set sql_mode='IGNORE_SPACE'; 再写concat得到正确结果

mysql workbench字体太小,函数和“(”之间有空格居然没看到。。。 php solr 搜索排序

 $response = $this->searchSolr->search( $query, $offset, $limit,array('sort'=>'wiki-recommend desc,wiki-score desc') ); 字符编码转换

string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )  cakePHP之XP下apache配置

php.ini文件设置 date.timezone = HongKong 不然cakePHP首页会出现警告

apache httpd.conf配置主要是设置php支持及urlrewrite模块启动

LoadModule php5_module C:/php/php5apache2_2.dll

AddType application/x-httpd-php .php
PHPIniDir "C:/php"

#使用cake php 则去掉下行的注释
LoadModule rewrite_module modules/mod_rewrite.so


DirectoryIndex index.html index.php


# 配置默认的目录设置 是否允许跳转.
#

Options FollowSymLinks
AllowOverride all
# Order deny,allow
# Deny from all


# This should be changed to whatever you set DocumentRoot to.
#这个目录的配置同上做更改 二维数组赋值

$a1 = array( "a" => 0, "b" => 1 );
$a2 = array( "aa" => 00, "bb" => 11 );
$together = array( $a1, $a2 );
foreach( $together as $single ) {
$single["c" ] = 3 ;
}

这样赋值不会有任何变化,必须如下做法:

foreach( $together as $key => $value ) {
$together[$key]["c"] = 3 ;
} 使用yum 安装和删除PHP
# rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# yum search php
# yum update php mysql导出数据
导出表结构 mysqldump --opt -d shorturl -htestdb -utest -ptest> test.sql
导出数据和表结构 mysqldump 数据库名 -uroot -p > xxx.sql  
导出数据 mysqldump -t 数据库名 -uroot -p > xxx.sql  
导出特定表mysqldump -uroot -p -B数据库名 --table 表名 > xxx.sql  
如出现无权限锁表问题  mysqldump --opt --single-transaction -d love  -ulove -plove> love.sql mysql slave 恢复:  Fixing MySQL replication after slaves's relay log was corrupted 
http://www.redips.net/mysql/replication-slave-relay-log-corrupted/
首先 show slave status\G;  记录两个值:Relay_Master_Log_File  Exec_Master_Log_Pos

OK, with this values, new binlog position can be set:

# stop slave

mysql> stop slave;

# make slave forget its replication position in the master's binary log

mysql> reset slave;

# change slave to start reading from stopped position

mysql> change master to master_log_file='mysql-bin.002045', master_log_pos=103641119;

# start slave

mysql> start slave;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template