my php & mysql FAQ

my php & mysql FAQ

  1. php Chinese character string length and fixed-length interception problem Use str_len("China"), the result is 6. The php system defaults a Chinese character length of 3, you can use the mb_strlen function to obtain the length, and the mb_substr function to intercept the characters mb_strlen($str, "utf -8");//1 Chinese character is 1 character mb_strlen($str, "gb2312");//The system will consider 1 Chinese character to be 2 characters mb_strlen($str);//If not added, the system will consider 1 Chinese character as 3 characters int mb_strlen (string str [, string encoding]) string mb_substr (string str, int start [, int length [, string encoding]])
  2. Determine whether the php variable is defined and empty if($keyword): If such a statement is not set in the controller, the judgment statement will be wrong, use the expression isset($keyword) instead, the expression 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
  3. Obtaining request multi-value parameters is similar to java request.getParameterValues() (I just knew this method, ==!) The background processing request in the page form $kword=$_POST['kword']; The corresponding method of cakePHP is $kword=$this ->params['form']['kword']; Use according to the order set when using $kword[index] index: 0-n
  4. php solr client api index not defined error when fetching the doc field. Solution: Some fields of the solr document may be incomplete. When taking multiple documents to display, if some fields have no defined values, an index not defined error will appear. Modify the solr client api Document File public function __get($key) {//If key does not exist, return empty to avoid index not defined error shen guanpu July 15, 2010 13:51:52 return array_key_exists($key,$this->_fields)?$ this->_fields[$key]:"";//return $this->_fields[$key]; original code}
  5. 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'); Source http ://www.chriscassell.net/log/2006/07/27/how_to_install_.html
  6. mysql remote access settings GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY'password' WITH GRANT OPTION; FLUSH PRIVILEGES;
  7. PHP closing tag The PHP closing tag "?>" is optional for the PHP parser in PHP. However, if a closed tag is used, any space after the closed tag inserted by the developer, user, or FTP application may cause redundant output, php error, subsequent output cannot be displayed, and a blank page. Therefore, all php files should omit this php closing tag, and insert a comment to indicate that this is the bottom of the file and locate the relative path of this file in this application. This will help you make sure that the file is closed and not truncated. INCORRECT: CORRECT:/* End of file myfile.php//Location: ./system/modules/mymodule/myfile.php */
  8. PHP judges the number bool is_numeric (mixed var)
  9. mysql IGNORE_SPACE mode Concat dose not exist error when writing concat function. Change set sql_mode='IGNORE_SPACE'; Write concat to get the correct result. The mysql workbench font is too small, and there is a space between the function and "(".
  10. php solr search sorting $response = $this->searchSolr->search( $query, $offset, $limit,array('sort'=>'wiki-recommend desc,wiki-score desc') );
  11. Character encoding conversion string mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
  12.  Apache configuration php.ini file setting date.timezone = HongKong under cakePHP XP, otherwise, a warning will appear on the cakePHP homepage apache httpd.conf configuration is mainly to set php support and urlrewrite module to start LoadModule php5_module C:/php/php5apache2_2.dll AddType application/x -httpd-php .php PHPIniDir "C:/php" #Using cake php, remove the comment on the bottom line LoadModule rewrite_module modules/mod_rewrite.so DirectoryIndex index.html index.php # Configure the default directory setting whether to allow redirection. # Options FollowSymLinks AllowOverride all # Order deny,allow # Deny from all # This should be changed to whatever you set DocumentRoot to. #The configuration of this directory is the same as above to make changes
  13. Two-dimensional array assignment $a1 = array( "a" => 0, "b" => 1 ); $a2 = array( "aa" => 00, "bb" => 11 ); $together = array( $ a1, $a2 ); foreach( $together as $single) {$single["c"] = 3;} There will be no change in the assignment, and the following must be done: foreach( $together as $key => $value) {$together[$key]["c"] = 3;}
  14. Use yum to install and remove 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
  15. mysql export data export table structure mysqldump --opt -d shorturl -htestdb -utest -ptest> test.sql export data and table structure mysqldump database name -uroot -p> xxx.sql export data mysqldump -t database name -uroot -p > xxx.sql export a specific table mysqldump -uroot -p -B database name --table table name> xxx.sql if there is a problem of unprivileged lock table mysqldump --opt --single-transaction -d love -ulove -plove> love .sql
  16. mysql slave recovery: Fixing MySQL replication after slaves's relay log was corrupted http://www.redips.net/mysql/replication-slave-relay-log-corrupted/First show slave status\G; Record two values: 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;
Reference: https://cloud.tencent.com/developer/article/1067238 my php & mysql FAQ-Cloud+Community-Tencent Cloud