As a novice in PHP, make a backup of your frequently used phpcode.
1: File Processing
1 //Read configuration startup is the specified file2Filepath=$argv[1];3 if(NULL==$filepath){4 Echo"File\n";5 return;6 }7 //file Processing8 $handle=fopen($filepath, ' R ');9 Ten while(!feof($handle)){ One $line=fgets($handle); A if(NULL!=$line&&Trim($line)!=""){ -Dealline ($line); - } the } - //Business Logic - functionDealline ($line){ - $line=Trim($line); + Echo $line." \ n "; -}
2: Database Operations
1 $host= "127.0.0.1:8888";2 $username= "Root";3 $password="";4 $db= "TestDB";5 $conn=mysql_connect($host,$username,$password);6 mysql_select_db($db,$conn);7 mysql_query(' Set names UTF8 ');8 9 //increase, more, deleteTen $sql= "INSERT, UPDATE, delete"; One $result=mysql_query($sql); A //query get new self-increment ID - $result=mysql_query("Select last_insert_id ()"); - $qRow=Mysql_fetch_row($result); the $id=$qRow[0]; - //Enquiry - $sql= "SELECT * from tbltest where sid=test"; - $result=mysql_query($sql); + $qRow=Mysql_fetch_row($result); - Var_dump($qRow);
Php_ Common Operation _ Read file _ database operation