Category Archives: Chỉ dẫn lập trình

Sắp xếp mảng theo cách bạn thích

<?php
    $arr = array(
        array('name' => 'n4', 'value' => 'v1'),
        array('name' => 'n5', 'value' => 'v2'),
        array('name' => 'n3', 'value' => 'v3'),
    );

    usort($arr, array("Comp", "mycmp"));
    class Comp {
        function mycmp($e1, $e2) {
            return strcmp($e1['name'], $e2['name']);
        }
    }
    print_r($arr);
?>

Read write cookie by Javascript

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

dollar character in Shell Programming

$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$= All the arguments on the command line.
$# The number of command line arguments.

ERROR 2006 (HY000): MySQL server has gone away

I have one file x.sql (size about 7M)
It’s content is only one line (query insert multiple rows), like that
INSERT INTO yume(name, title) VALUES (‘-khung_long-‘, ‘-khung_long-‘),(‘0313577642’, ‘tinh_xa_vang_1981’),….

I used mysql client to import data via command
mysql> source C:\Documents and Settings\LNV\Desktop\tmp\yume\logs\x.sql
But I got error
ERROR 2006 (HY000): MySQL server has gone away

Solved:
In my.ini (MySQL Server configuration file)

my.ini configuration

my.ini configuration

One my batch script

File: C:\command-line\checkphp.bat
@echo off
cls
REM Luu thong tin o dia va thu muc dang lam viec
set odia=%cd:~0,2%
set thumuc=%cd%

REM Chuyen sang o dia va thuc muc chua batch script
%~d0
cd %~dp0

REM Lam mot so thu…
REM php -d “include_path=\”C:\;C:\var\includes;C:\var\www\includes\”” -r “print ini_get(‘include_path’);”
php –ini
php -r “define(‘ENTER’, \”\n\”); print ‘Include Path: ‘ . ini_get(‘include_path’); echo ENTER; echo (function_exists(‘curl_init’)) ? ‘cURL is available’: ‘cURL is unavailable’; echo ENTER; echo (function_exists(‘imagecreatefrompng’)) ? ‘Image Processing GD is available’ : ‘Image Processing GD is unavailable’; ”

REM Quay tro lai o dia va thu muc dang lam viec ban dau
%odia%
cd %thumuc%

Set thêm biến môi trường C:\command-line\ vào trong PATH (chuột phải My Computer, Properties, Advanced, Environment Variables, System variables, Path)

Run
cmd
checkphp

Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\xampplite\php\php-cli.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Include Path: .;C:\xampplite\php\pear
cURL is available
Image Processing GD is available