search
HomeBackend DevelopmentPHP TutorialCollection of PHP knowledge I learned while working on projects_PHP tutorial

Collection of PHP knowledge I learned while working on projects_PHP tutorial

Jul 21, 2016 pm 03:17 PM
leftphpsqlexistcollectconditionAdd toofKnowledgeOwnstatementlimitproject

1 In the SQL statement, you can add restrictions: left(text,20) only takes the first 20 characters of the text;

2 You can use limit fromRecord, RecordNum for paging, such as limit 0,30 Indicates traversing 30 records starting from the first record;

3 The connection between the two tables can be: table1 join table2 using x (x is the common field of the two tables), or table1 join table2 on table1 .x = table2.x

4 PHP can use $page = $_GET['page'];

or

$page = $_REQUEST['page '];

Where Request can obtain post, get, QueryString and other characters;

Before this I saw a stupid way:

parse_str($_SERVER[ 'QUERY_STRING'],$output); // First save the query string into an array $output

  $page = $output['page']; // Then index according to the variable name

5 The comparison of date functions in php is actually the comparison of strings;

6 The date type data in mysql can be: 2000-02-03, 2002.02.03, 2002.2.3, 02.02. 03,02.2.3, that is to say, there must be month and day, and they must be separated by '-' or '.'.

7 There is a time zone problem when using data() to get the time. I found that the time is 8 hours shorter because the default configuration in php.ini is GTM US time zone;

Solution : You can modify php.ini:

[Date]

; Defines the default timezone used by the date functions

date.timezone = "Asia/Shanghai"

Or when using the date() function, add date_Default_TimeZone_set("PRC");

8 For a while, when debugging, it always said that I was missing ")" in the body. It took a long time to find intval( $_POST['consumeType']) problem. In the database, the field is varchar(50). In the zengsong table, I did not use the intval function because its ID is 1, 2... Integer and char types can be used. Convert each other, but in the other two tables it is A5A, SP07-01, etc., but how is it converted to int type?

Let us take a look at the declaration of the intval function:

The intval function is used to get the integer value of a variable: int intval ( mixed var [, int base] )

By using a specific base conversion (the default is decimal), the integer value of the variable var is returned.

var can be any scalar type. intval() cannot be used with array or object.

9 Another inexplicable problem, if you log in with user name 1, then log in with 'bo', the system will go wrong: it says I have a running time error: missing ")", nnd. After checking, it turns out that the variable type in the sql statement is inconsistent with that in the database.

10 When converting from a floating point number to an integer in php, the number will be rounded (the decimal places are discarded).

11 In the mysql insert statement, if it is an auto-increment field, use (NULL) instead.

12 php Chinese garbled characters??? Problem solution:

Add mysql_query("set names 'gb2312'");

or use utf8 encoding after mysql_connect. There is no need to add the above statement.

There is also the function iconv("GBK", "UTF8", "String"); which can convert various character encodings.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325726.htmlTechArticle1 In the SQL statement, you can add restrictions: left(text,20) to only take the first 20 text text characters; 2 You can use limit fromRecord, RecordNum for paging, for example, limit 0,30 means starting from the first...
Statement
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools