my php & mysql FAQ
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; |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
