Archive

Archive for May, 2012

Get next MySQL Auto Increment

May 12, 2012 Leave a comment

function nextAi($table_name) {
$r = mysql_query(“SHOW TABLE STATUS LIKE ‘$table_name'”);
$row = mysql_fetch_array($r);
$auto_increment = $row[‘Auto_increment’];
mysql_free_result($r);
return $auto_increment;
}

วิธีนี้จะให้ผลลัพธ์ที่ตรงกว่าการใช้ Max (id) + 1 เพราะสมมุติว่าสูงสุดคือไอดี 40 และโดนลบไป Max (id) + 1 ก็จะเท่ากับ 40 เหมือนเดิม ซึ่งจริง ๆ แล้ว Table รันไปถึงเลข 41 แล้ว การใช้วิธีนี้จะเป็นการดึง AI จาก Table ที่ต้องการโดยตรง

Categories: PHP Tags: , ,

Facebook Batch Upload API

May 2, 2012 Leave a comment
 
$files = array(
    '/data/Pictures/pic1.jpg',
    '/data/Pictures/pic2.jpg',
    '/data/Pictures/pic3.jpg'
);

//Must set upload support to true
$facebook->setFileUploadSupport(true);

$batch     = array();
$params    = array();
$count = 1;
foreach($files as $file){
    $req = array(
        'method'         => 'POST',
        'relative_url'   => '/me/photos',
        'attached_files' => 'file' . $count
    );
    //add this request to the batch ...
    $batch[] = json_encode($req);

    //set the filepath for the file to be uploaded
    $params['file'.$count] = '@' . realpath($file);

    $count++;
}
$params['batch'] = '[' . implode(',',$batch) . ']';

try{
    $upload = $facebook->api('/','post',$params);
} catch(FacebookApiException $e) {
    error_log($e);
    $upload = null;
}

//View the results ...
if(!is_null($upload)){
    echo "<pre>" . print_r($upload,1) . "<pre>";
    echo "<hr />";
}

Categories: PHP Tags: , , ,