Free Hosting

วันศุกร์ที่ 14 มีนาคม พ.ศ. 2568

การดึง api ใน google sheet มาแสดง ที่ไม่ต้องใช้ package business plan

0 ความคิดเห็น

สำหรับ WordPress ที่ใช้แผนฟรีหรือแผนส่วนตัว (Personal Plan) และต้องการดึงข้อมูลจาก Google Sheets โดยไม่ต้องใช้ปลั๊กอินที่ต้องการ Business Plan แนะนำวิธีดังนี้:

1. ใช้ปลั๊กอินฟรีที่รองรับ Google Sheets API

คุณสามารถใช้ปลั๊กอินฟรี เช่น:

  • WP Table Builder (เหมาะสำหรับแสดงข้อมูลเป็นตาราง)
  • Inline Google Spreadsheet Viewer (ดึงข้อมูลจาก Google Sheets มาแสดงในรูปแบบ HTML)
  • TablePress + TablePress Extension: Automatic URL Import (สามารถอัปเดตข้อมูลจาก Google Sheets อัตโนมัติ)

ขั้นตอนการใช้ Inline Google Spreadsheet Viewer

  1. ติดตั้งปลั๊กอิน Inline Google Spreadsheet Viewer จาก WordPress Plugin Directory
  2. เปิด Google Sheets และแชร์ไฟล์แบบ "Anyone with the link"
  3. คัดลอก Sheet URL
  4. ใช้ Shortcode เช่น:
    [gdoc key="URL_GOOGLE_SHEET"]
    
    หรือใช้ Table Format:
    [gdoc key="URL_GOOGLE_SHEET" class="my-table"]
    

2. ใช้ Custom HTML + Google Sheets API

หากต้องการให้ข้อมูลอัปเดตเรียลไทม์ สามารถใช้ Google Sheets API + JavaScript ได้โดยไม่ต้องใช้ปลั๊กอิน เช่น:

ขั้นตอนการทำ

  1. เปิด Google Sheets และแชร์แบบ "Anyone with the link"
  2. คัดลอก Sheet ID จาก URL
    ตัวอย่าง URL:
    https://docs.google.com/spreadsheets/d/1A2B3C4D5E6F7G8H9I0/edit#gid=0
    
    Sheet ID คือ 1A2B3C4D5E6F7G8H9I0
  3. เพิ่มโค้ด Custom HTML + JavaScript ใน WordPress ไปที่ Custom HTML Block แล้ววางโค้ด:
    <div id="listings"></div>
    
    <script>
    async function fetchGoogleSheetData() {
        const sheetId = "1A2B3C4D5E6F7G8H9I0";
        const sheetName = "Sheet1"; // เปลี่ยนตามชื่อ Sheet ของคุณ
        const url = `https://docs.google.com/spreadsheets/d/${sheetId}/gviz/tq?tqx=out:json&sheet=${sheetName}`;
    
        const response = await fetch(url);
        const text = await response.text();
        const json = JSON.parse(text.substring(47, text.length - 2));
    
        let html = "";
        json.table.rows.forEach(row => {
            const imageUrl = row.c[0].v;
            const title = row.c[1].v;
            const price = row.c[2].v;
            const location = row.c[3].v;
    
            html += `
                <div style="display: flex; border: 1px solid #ddd; margin-bottom: 10px; padding: 10px;">
                    <img src="${imageUrl}" style="width: 100px; height: 100px; object-fit: cover; margin-right: 10px;">
                    <div>
                        <h3>${title}</h3>
                        <p>฿ ${price}</p>
                        <p>📍 ${location}</p>
                    </div>
                </div>
            `;
        });
    
        document.getElementById("listings").innerHTML = html;
    }
    
    fetchGoogleSheetData();
    </script>
    

สรุป

  • หากต้องการปลั๊กอิน → ใช้ Inline Google Spreadsheet Viewer หรือ TablePress
  • หากต้องการใช้โค้ดเอง → ใช้ Google Sheets API + JavaScript
  • ไม่ต้องใช้ Business Plan → ใช้วิธีดึง JSON จาก Google Sheets ผ่าน Google Visualization API
Read full post »

วันอาทิตย์ที่ 9 มีนาคม พ.ศ. 2568

ปัญหากับปลั๊กอินหรือธีมที่ใช้งานอยู่บนเว็บไซต์ของคุณ โดยเฉพาะถ้าคุณใช้ WordPress

0 ความคิดเห็น


 ดูเหมือนว่าอาจมีปัญหากับปลั๊กอินหรือธีมที่ใช้งานอยู่บนเว็บไซต์ของคุณ โดยเฉพาะถ้าคุณใช้ WordPress และมีปลั๊กอินที่เกี่ยวข้องกับการสร้างฟอร์ม (เช่น Contact Form 7, WPForms, Gravity Forms ฯลฯ) ลองทำตามวิธีแก้ไขต่อไปนี้:

วิธีแก้ไขเบื้องต้น

1. ปิดปลั๊กอินที่เกี่ยวข้องกับฟอร์ม

ไปที่ Plugins → Installed Plugins แล้วลอง Deactivate ปลั๊กอินที่เกี่ยวข้องกับการสร้างฟอร์ม

รีเฟรชหน้าและลองเข้าไปแก้ไข Page อีกครั้ง

2. สลับไปใช้ธีมเริ่มต้นของ WordPress

ไปที่ Appearance → Themes

ลองเปลี่ยนเป็นธีมเริ่มต้น เช่น Twenty Twenty-Four

ทดสอบอีกครั้งว่าปัญหายังเกิดขึ้นหรือไม่

3. เคลียร์ Cache และ Cookies

ลองเปิดหน้าเว็บในโหมด Incognito หรือใช้เบราว์เซอร์อื่น

หากยังมีปัญหา ให้ลองเคลียร์แคชของเว็บไซต์ (หากใช้ปลั๊กอิน Cache เช่น WP Rocket, W3 Total Cache หรือ LiteSpeed Cache)

4. ตรวจสอบ JavaScript Error

เปิด Developer Tools (F12 หรือ Ctrl + Shift + I บน Chrome/Firefox)

ไปที่ Console และดูว่ามีข้อผิดพลาด JavaScript หรือไม่

ถ้ามี Error เช่น Uncaught TypeError หรือ jQuery is not defined อาจต้องอัปเดตปลั๊กอินหรือตรวจสอบว่า jQuery โหลดไม่สมบูรณ์

5. ตรวจสอบการอัปเดตปลั๊กอินและ WordPress

ตรวจสอบว่าทั้ง WordPress, ปลั๊กอิน และธีมเป็นเวอร์ชันล่าสุดหรือไม่

อัปเดตทุกอย่างให้เป็นเวอร์ชันล่าสุด

6. ลองเพิ่มโค้ดปิด Gutenberg Block Editor

ถ้าคุณใช้ Classic Editor ให้ลองเพิ่มโค้ดนี้ใน functions.php ของธีม:


add_filter('use_block_editor_for_post', '__return_false', 10);


7. รีเซ็ตการตั้งค่าปลั๊กอิน

หากคุณมีปลั๊กอินสร้างฟอร์ม ให้ลองรีเซ็ตการตั้งค่าเป็นค่าเริ่มต้น

ถ้ายังแก้ไม่ได้

หากยังมีปัญหา อาจต้องตรวจสอบไฟล์เว็บไซต์โดยตรงผ่าน FTP หรือ File Manager เพื่อดูว่ามีข้อผิดพลาดหรือไฟล์ที่ขัดแย้งกันอยู่หรือไม่

คุณลองวิธีไหนแล้วบ้าง หรืออยากให้ช่วยตรวจสอบอะไรเพิ่มเติมไหม?



Read full post »

Apache ใน XAMPP หรือ MAMP Start ไม่ได้ อาจเกิดจากหลายสาเหตุ

0 ความคิดเห็น

 Apache ใน XAMPP หรือ MAMP Start ไม่ได้ อาจเกิดจากหลายสาเหตุ นี่คือสาเหตุที่พบบ่อยและวิธีแก้ไข:

1️⃣ มีโปรแกรมอื่นใช้พอร์ต 80 หรือ 443

สาเหตุ:

Skype, IIS, TeamViewer, VMware, หรือโปรแกรมอื่น อาจใช้ พอร์ต 80 หรือ 443 (HTTPS)

วิธีแก้:

เปลี่ยนพอร์ตของ Apache ไปเป็น 8080 หรือ 8000

1. เปิด XAMPP Control Panel → คลิก Config ในช่อง Apache → เลือก httpd.conf

2. หา Listen 80 → เปลี่ยนเป็น Listen 8080

3. หา ServerName localhost:80 → เปลี่ยนเป็น ServerName localhost:8080

4. บันทึกไฟล์แล้ว Restart Apache

5. เข้าเว็บโดยใช้ http://localhost:8080

2️⃣ มีโปรแกรมที่ใช้ MySQL หรือ MariaDB อยู่

สาเหตุ:

ถ้า Apache Start ไม่ได้และมี MySQL/MariaDB ทำงาน อาจเป็นเพราะ MySQL ใช้พอร์ตเดียวกันกับ Apache

วิธีแก้:

ลองปิด MySQL ใน XAMPP ก่อนแล้ว Start Apache ใหม่

หรือเปลี่ยนพอร์ต MySQL ที่ my.ini (ใน XAMPP/mysql/bin/)

3️⃣ พอร์ตถูกบล็อกโดย Firewall หรือ Antivirus

สาเหตุ:

บางครั้ง Windows Defender, Firewall, หรือโปรแกรม Antivirus บล็อก Apache

วิธีแก้:

ปิด Firewall ชั่วคราว:

1. เปิด Control Panel → ไปที่ Windows Defender Firewall

2. คลิก Turn Windows Defender Firewall on or off

3. เลือก Turn off Windows Defender Firewall ทั้งสองช่อง

4. ลอง Start Apache ใหม่

ปิด Antivirus หรือเพิ่ม Apache ไว้ใน Whitelist

4️⃣ มี Apache หรือ IIS ตัวอื่นรันอยู่

สาเหตุ:

ถ้าติดตั้ง IIS (Internet Information Services) หรือ มี Apache อีกตัว อาจทำให้พอร์ตชนกัน

วิธีแก้:

ปิด IIS:

1. กด Win + R → พิมพ์ services.msc แล้ว Enter

2. หา World Wide Web Publishing Service

3. คลิกขวา → เลือก Stop

เช็คว่ามี Apache รันอยู่ไหม:

netstat -ano | findstr :80

ถ้ามี Process ID (PID) ให้ไปที่ Task Manager → หยุดโปรเซสนั้น

5️⃣ Apache มีไฟล์ config ผิดพลาด

สาเหตุ:

ไฟล์ httpd.conf หรือ httpd-vhosts.conf อาจผิดพลาด

วิธีแก้:

เปิด httpd.conf แล้วตรวจสอบว่ามีการตั้งค่าโฮสต์เสมือน (Virtual Host) ที่ผิดหรือไม่

ลองรีเซ็ตค่ากลับไปเป็นค่าเริ่มต้นของ XAMPP แล้วลองรันใหม่

6️⃣ Permission ไม่พอ (เฉพาะ macOS/Linux)

สาเหตุ:

ถ้าใช้ macOS หรือ Linux อาจต้องรัน Apache ด้วยสิทธิ์ root

วิธีแก้:

sudo /Applications/XAMPP/xamppfiles/bin/apachectl start


🔥 สรุป

✅ ลองทำตามลำดับนี้:

1. เปลี่ยนพอร์ต Apache เป็น 8080

2. ปิด IIS และโปรแกรมที่ใช้พอร์ต 80

3. ปิด Firewall / Antivirus ชั่วคราว

4. ตรวจสอบและแก้ไข httpd.conf

ถ้ายัง Start ไม่ได้ บอกผมได้เลยว่าขึ้น Error อะไร เดี๋ยวช่วยแก้ให้ละเอียดขึ้น!



Read full post »

วันจันทร์ที่ 17 กุมภาพันธ์ พ.ศ. 2568

คำสั่ง tag

0 ความคิดเห็น
รูปแบบของ tag 

รูปแบบของ tag แบ่งออกเป็น 2 กลุ่ม คือ

1. tag เดี่ยว
คือ รูปแบบค าสั่งที่มีเพียงค าสั่งเดียวหรือมีเพียงแท็กเดียว ก็สามารถใช้งานได้ เช่น <br>

2. tag คู่
คือ รูปแบบค าสั่งที่เป็นสองส่วน คือ มีส่วนเริ่มต้นและต้องมีส่วนจบของค าสั่งถึงจะสามารถท างานได้
สมบูรณ์ โดยส่วนจบของแต่ละค าสั่งจะมีเครื่องหมาย Slash (/) ไว้หน้าแท็กค าสั่งนั้น เช่น
<html>......</html>


tag คู่ มีทั้งหมด 4 แท็ก คือ
1. <html>...</html>
2. <head>....</head>
3. <title>....</title>
4. <body>....</body>

tag เดี่ยว มีทั้งหมด 1 แท็ก คือ <br>


tag คำสั่งหลัก ของการเขียนโปรแกรมด้วยภาษา HTML

การเขียนโปรแกรมด้วยภาษา HTML จะมีโครงสร้างและการจัดวางค าสั่งหลักที่เป็น
มาตรฐานเหมือนกันทั่งโลก โดยจะประกอบด้วยค าสั่งหลักๆ อยู่ 4 ค าสั่งด้วยกัน ดังนี้

1. <html>........</html>
เป็นค าสั่งที่ท าหน้าที่บอกจุดเริ่มต้นและจุดสิ้นสุดของเอกสาร HTML

2. <head>........</head>
เป็นค าสั่งที่ท าหน้าที่ก าหนดส่วนหัวเรื่อง

3. <title>.........</title>
เป็นค าสั่งที่ใช้ก าหนดข้อความที่ต้องการน ามาแสดงผลบนแถบ Title Bar ค าสั่งนี้จะอยู่ภายในค าสั่ง
ส่วน <head>......</head> โดยก าหนดความยาวของตัวอักษรไม่เกิน 64 ตัวอักษร

4. <body>.........</body>
เป็นค าสั่งที่ก าหนดข้อความและรูปแบบของค าสั่งต่างๆ ที่ใช้ส าหรับปรับแต่งเอกสารที่จะน าเสนอออก
ทางส่วนแสดงผลหลักของ Web Browser


ขอบคุณข้อมูลจาก : http://www.saensuk.ac.th/html/k1.pdf
Read full post »

วันเสาร์ที่ 1 กุมภาพันธ์ พ.ศ. 2568

การสร้างระบบ Login ด้วย Facebook บนเว็บไซต์

0 ความคิดเห็น

 การสร้างระบบ Login ด้วย Facebook บนเว็บไซต์สามารถทำได้โดยใช้ Facebook Login API ซึ่งต้องผ่านขั้นตอนหลักดังนี้:

1. สร้างแอปบน Facebook Developer

1. ไปที่ Meta for Developers

2. ลงชื่อเข้าใช้ด้วยบัญชี Facebook

3. คลิก "Create App" และเลือกประเภทแอปเป็น Consumer

4. กรอกข้อมูลและเลือก Facebook Login เป็นผลิตภัณฑ์ที่ต้องการใช้

5. หลังจากสร้างแอปแล้ว คุณจะได้รับ App ID และ App Secret


2. ตั้งค่า OAuth และ Redirect URL

1. ไปที่ Settings > Basic และเพิ่ม Website URL ของคุณ

2. ไปที่ Facebook Login > Settings

เปิด Client OAuth Login และ Web OAuth Login

เพิ่ม Valid OAuth Redirect URIs เป็น URL สำหรับรับข้อมูลล็อกอิน เช่น:

https://yourwebsite.com/fb-callback.php


3. เพิ่มปุ่ม Facebook Login บนหน้าเว็บ

เพิ่มปุ่ม Login with Facebook ลงในไฟล์ HTML:


<!DOCTYPE html>

<html lang="th">

<head>

    <meta charset="UTF-8">

    <title>Facebook Login</title>

    <script>

        window.fbAsyncInit = function() {

            FB.init({

                appId : 'YOUR_APP_ID', // ใส่ App ID ที่ได้รับ

                cookie : true,

                xfbml : true,

                version : 'v18.0' // ใช้เวอร์ชันล่าสุด

            });

        };


        function fbLogin() {

            FB.login(function(response) {

                if (response.authResponse) {

                    window.location.href = "fb-callback.php?access_token=" + response.authResponse.accessToken;

                } else {

                    console.log("User cancelled login or did not fully authorize.");

                }

            }, {scope: 'email,public_profile'});

        }

    </script>

</head>

<body>

    <button onclick="fbLogin()">Login with Facebook</button>


    <script async defer crossorigin="anonymous" 

        src="https://connect.facebook.net/en_US/sdk.js"></script>

</body>

</html>


4. สร้างไฟล์ fb-callback.php เพื่อรับข้อมูลผู้ใช้

เมื่อผู้ใช้ล็อกอินแล้ว ระบบจะส่ง access token ไปยัง fb-callback.php ซึ่งจะใช้ดึงข้อมูลผู้ใช้จาก Facebook API:


<?php

session_start();


// ใส่ Facebook App ID และ Secret

$app_id = 'YOUR_APP_ID';

$app_secret = 'YOUR_APP_SECRET';


// รับ Access Token จาก URL

if (isset($_GET['access_token'])) {

    $access_token = $_GET['access_token'];


    // ดึงข้อมูลผู้ใช้จาก Facebook API

    $url = "https://graph.facebook.com/me?fields=id,name,email&access_token=" . $access_token;

    $response = file_get_contents($url);

    $user = json_decode($response, true);


    if (isset($user['id'])) {

        $_SESSION['user_id'] = $user['id'];

        $_SESSION['user_name'] = $user['name'];

        $_SESSION['user_email'] = isset($user['email']) ? $user['email'] : 'No email provided';


        echo "ยินดีต้อนรับ, " . $_SESSION['user_name'];

    } else {

        echo "เกิดข้อผิดพลาดในการล็อกอิน";

    }

} else {

    echo "ไม่พบ Access Token";

}

?>


5. ทดสอบระบบ

1. เปิดหน้าเว็บ index.html และลองคลิกปุ่ม Login with Facebook

2. หากเข้าสู่ระบบสำเร็จ คุณจะถูกเปลี่ยนหน้าไปที่ fb-callback.php พร้อมแสดงข้อมูลชื่อและอีเมล


6. ปรับแต่งและบันทึกข้อมูลลงฐานข้อมูล (Optional)

หากต้องการบันทึกข้อมูลลง MySQL สามารถเพิ่มโค้ดลงใน fb-callback.php ได้:


$mysqli = new mysqli("localhost", "root", "", "your_database");


if ($mysqli->connect_error) {

    die("Connection failed: " . $mysqli->connect_error);

}


$user_id = $mysqli->real_escape_string($user['id']);

$name = $mysqli->real_escape_string($user['name']);

$email = isset($user['email']) ? $mysqli->real_escape_string($user['email']) : '';


$sql = "INSERT INTO users (facebook_id, name, email) VALUES ('$user_id', '$name', '$email') 

        ON DUPLICATE KEY UPDATE name='$name', email='$email'";


if ($mysqli->query($sql)) {

    echo "บันทึกข้อมูลเรียบร้อย";

} else {

    echo "Error: " . $mysqli->error;

}

$mysqli->close();


สรุป

1. สร้างแอปใน Facebook Developer

2. ตั้งค่า OAuth และ Redirect URL

3. เพิ่มปุ่ม Login with Facebook บนหน้าเว็บ

4. ดึงข้อมูลผู้ใช้ด้วย PHP ผ่าน Facebook Graph API

5. (Optional) บันทึกข้อมูลลงฐานข้อมูล MySQL


หากมีข้อสงสัยเพิ่มเติม แจ้งมาได้ครับ!

Read full post »

วันพุธที่ 29 มกราคม พ.ศ. 2563

PHP 5.2 UPDATE

0 ความคิดเห็น
php 5.2 เปลี่ยนแปลง ครั้งใหญ่? เกี่ยว
OpenSSL update 0.9.8d
libraries สำหรับ Postgresql และ MySQL สำหรับ windows
เพิ่ม hexadecimal entity in imagettftext() เพิ่ม function array_fill_keys() และ function อื่น อีกมามาย? ตรวจจน fixbug ต่างๆ

Version 5.2.0

02-Nov-2006
  • Updated bundled OpenSSL to version 0.9.8d in the Windows distro. (Edin)
  • Updated Postgresql client libraries to 8.1.4 in the Windows distro. (Edin)
  • Updated PCRE to version 6.7. (Ilia)
  • Updated libsqlite in ext/pdo_sqlite to 3.3.7. (Ilia)
  • Updated bundled MySQL client library to version 5.0.22 in the Windows distribution. (Edin)
  • Updated timezonedb to version 2006.14. (Derick)
  • Added ability to make SOAP call userspace PHP<->XML converters. (Dmitry)
  • Added support for character sets in pg_escape_string() for PostgreSQL 8.1.4 and higher. (Ilia)
  • Added support for character sets in PDO quote() method for PostgreSQL 8.1.4 and higher. (Ilia)
  • Added DSA key generation support to openssl_pkey_new(), FR #38731 (marci at balabit dot hu, Tony)
  • Added SoapServer::setObject() method (it is a simplified version of SoapServer::setClass() method). (Dmitry)
  • Added support for hexadecimal entity in imagettftext() for the bundled GD. (Pierre)
  • Added support for httpOnly flag for session extension and cookie setting functions. (Scott MacVicar, Ilia)
  • Added version specific registry keys to allow different configurations for different php version. (Richard, Dmitry)
  • Added "PHPINIDir" Apache directive to apache and apache_hooks SAPIs. (Dmitry)
  • Added an optional boolean parameter to memory_get_usage() and memory_get_peak_usage() to get memory size allocated by emalloc() or real size of memory allocated from system. (Dmitry)
  • Added Zip Archive extension. (Pierre)
  • Added RFC1867 fileupload processing hook. (Stefan E.)
  • Added JSON and Filter extensions. (Derick, Rasmus, Pierre, Ilia)
  • Added error messages to disk_free_space() and disk_total_space() functions. FR #37971 (Tony)
  • Added PATHINFO_FILENAME option to pathinfo() to get the filename. (Toby S. and Christian S.)
  • Added array_fill_keys() function. (Marcus, Matt Wilmas)
  • Added posix_initgroups() function. (Ilia)
  • Added an optional parameter to parse_url() to allow retrieval of distinct URL components. (Ilia)
  • Added optional parameter to http_build_query() to allow specification of string separator. (Ilia)
  • Added image_type_to_extension() function. (Hannes, Ilia)
  • Added allow_url_include ini directive to complement allow_url_fopen. (Rasmus)
  • Added automatic module globals management. (Dmitry)
  • Added RFC2397 (data: stream) support. (Marcus)
  • Added new error mode E_RECOVERABLE_ERROR. (Derick, Marcus, Tony)
  • Added support for getenv() input filtering. (Rasmus)
  • Added support for constructors in interfaces to force constructor signature checks in implementations. (Marcus)
  • Added memory_get_peak_usage() function for retrieving peak memory usage of a PHP script. (Ilia)
  • Added pg_field_table() function. (Edin)
  • Added SimpleXMLElement::saveXML() as an alias for SimpleXMLElement::asXML(). (Hannes)
  • Added DOMNode::getNodePath() for getting an XPath for a node. (Christian)
  • Added gmp_nextprime() function. (ants dot aasma at gmail dot com, Tony)
  • Added error_get_last() function. (Mike)
  • Removed current working directory from the php.ini search path for CLI and re-added it for other SAPIs (restore to pre 5.1.x behavior). (Edin)
  • Moved extensions to PECL:
    • ext/filepro (Derick, Tony)
    • ext/hwapi (Derick, Tony)
  • Disabled CURLOPT_FOLLOWLOCATION in curl when open_basedir or safe_mode are enabled. (Stefan E., Ilia)
  • Increased default memory limit to 16 megabytes to accommodate for a more accurate memory utilization measurement.
  • In addition to path to php.ini, PHPRC now may specify full file name. (Dmitry)
  • Optimized array/HashTable copying. (Matt Wilmas, Dmitry)
  • Optimized zend_try/zend_catch macros by eliminating memcpy(3). (Dmitry)
  • Optimized require_once() and include_once() by eliminating fopen(3) on second usage. (Dmitry)
  • Optimized request shutdown sequence. Restoring ini directives now iterates only over modified directives instead of all. (Dmitry)
  • Changed priority of PHPRC environment variable on win32 to be higher then value from registry. (Dmitry)
  • Changed __toString() to be called wherever applicable. (Marcus)
  • Changed E_ALL error reporting mode to include E_RECOVERABLE_ERROR. (Marcus)
  • Changed realpath cache to be disabled when "open_basedir" or "safe_mode" are enabled on per-request basis. (Ilia)
  • Improved SNMP extension: (Jani)
    • Renamed snmp_set_oid_numeric_print() to snmp_set_oid_output_format().
    • Added 2 new constants: SNMP_OID_OUTPUT_FULL and SNMP_OID_OUTPUT_NUMERIC
    • Fixed bug #37564 (AES privacy encryption not possible due to net-snmp 5.2 compatibility issue). (Patch: scott dot moynes+php at gmail dot com)
  • Improved OpenSSL extension: (Pierre)
    • Added support for all supported algorithms in openssl_verify
    • Added openssl_pkey_get_details, returns the details of a key
    • Added x509 v3 extensions support
    • Added openssl_csr_get_subject() and openssl_csr_get_public_key()
    • Added 3 new constants OPENSSL_VERSION_TEXT and OPENSSL_VERSION_NUMBER and OPENSSL_KEYTYPE_EC
  • Improved the Zend memory manager: (Dmitry)
    • Removed unnecessary "--disable-zend-memory-manager" configure option.
    • Added "--enable-malloc-mm" configure option which is enabled by default in debug builds to allow using internal and external memory debuggers.
    • Allow tweaking the memory manager with ZEND_MM_MEM_TYPE and ZEND_MM_SEG_SIZE environment variables.
    • For more information: Zend/README.ZEND_MM
  • Improved safe_mode check for the error_log() function. (Ilia)
  • Improved the error reporting in SOAP extension on request failure. (Ilia)
  • Improved crypt() on win32 to be about 10 times faster and to have friendlier license. (Frank, Dmitry)
  • Improved performance of the implode() function on associated arrays. (Ilia)
  • Improved performance of str_replace() when doing 1 char to 1 char or 1 char to many chars replacement. (Ilia)
  • Improved apache2filter SAPI:
    • Allowed PHP to be an arbitrary filter in the chain and read the script from the Apache stream. (John)
    • Added support for apache2filter in the Windows build including binary support for both Apache 2.0.x (php5apache2_filter.dll) and Apache 2.2.x (php5apache2_2_filter.dll). (Edin)
  • Improved apache2handler SAPI:
    • Changed ap_set_content_type() to be called only once. (Mike)
    • Added support for Apache 2.2 handler in the Windows distribution. (Edin)
  • Improved FastCGI SAPI: (Dmitry)
    • Removed source compatibility with libfcgi.
    • Optimized access to FastCGI environment variables by using HashTable instead of linear search.
    • Allowed PHP_FCGI_MAX_REQUESTS=0 that assumes no limit.
    • Allowed PHP_FCGI_CHILDREN=0 that assumes no worker children. (FastCGI requests are handled by main process itself)
  • Improved CURL:
    • Added control character checks for "open_basedir" and "safe_mode" checks. (Ilia)
    • Added implementation of curl_multi_info_read(). (Brian)
  • Improved PCRE: (Andrei)
    • Added run-time configurable backtracking/recursion limits.
    • Added preg_last_error(). (Andrei)
  • Improved PDO:
    • Added new attribute ATTR_DEFAULT_FETCH_MODE. (Pierre)
    • Added FETCH_PROPS_LATE. (Marcus)
  • Improved SPL: (Marcus)
    • Made most iterator code exception safe.
    • Added RegExIterator and RecursiveRegExIterator.
    • Added full caching support and ArrayAccess to CachingIterator.
    • Added array functions to ArrayObject/ArrayIterator and made them faster.
    • Added support for reading csv and skipping empty lines in SplFileObject.
    • Added CachingIterator::TOSTRING_USE_INNER, calls inner iterator __toString.
    • Added ability to set the CSV separator per SplFileObject.
  • Improved xmlReader: (Rob)
    • Added readInnerXml(), xmlReader::setSchema().
    • Added readInnerXML(), readOuterXML(), readString(), setSchema(). (2.6.20+)
    • Changed to passing libxml options when loading reader.
  • Fixed invalid read in imagecreatefrompng when an empty file is given (Pierre, Tony)
  • Fixed infinite loop when a wrong color index is given to imagefill (Pierre)
  • Fixed mess with CGI/CLI -d option (now it works with cgi; constants are working exactly like in php.ini; with FastCGI -d affects all requests). (Dmitry)
  • Fixed missing open_basedir check inside chdir() function. (Ilia)
  • Fixed overflow on 64bit systems in str_repeat() and wordwrap(). (Stefan E.)
  • Fixed XSLTProcessor::importStylesheet() to return TRUE on success (Christian)
  • Fixed leaks in openssl_csr_sign and openssl_csr_new (Pierre)
  • Fixed phpinfo() cutoff of variables at ?. (Ilia)
  • Fixed a bug in the filter extension that prevented magic_quotes_gpc from being applied when RAW filter is used. (Ilia)
  • Fixed memory leaks in openssl streams context options. (Pierre)
  • Fixed handling of extremely long paths inside tempnam() function. (Ilia)
  • Fixed bug #39304 Segmentation fault with list unpacking of string offset). (Dmitry)
  • Fixed bug #39192 Not including nsapi.h properly with SJSWS 7). This will make PHP 5.2 compatible to new Sun Webserver. (Uwe)
  • Fixed bug #39140 Uncaught exception may cause crash). (Dmitry)
  • Fixed bug #39125 Memleak when reflecting non-existing class/method). (Tony)
  • Fixed bug #39067 getDeclaringClass() and private properties). (Tony)
  • Fixed bug #39039 SSL: fatal protocol error when fetching HTTPS from servers running Google web server). (Ilia)
  • Fixed bug #39035 Compatibility issue between DOM and zend.ze1_compatibility_mode). (Rob)
  • Fixed bug #39034 curl_exec() with return transfer returns TRUE on empty files). (Ilia)
  • Fixed bug #39032 strcspn() stops on null character). (Tony)
  • Fixed bug #39020 PHP in FastCGI server mode crashes). (Dmitry)
  • Fixed bug #39017 foreach(($obj = new myClass) as $v); echo $obj; segfaults). (Dmitry)
  • Fixed bug #39004 Fixed generation of config.nice with autoconf 2.60). (Ilia)
  • Fixed bug #39003 __autoload() is called for type hinting). (Dmitry, Tony)
  • Fixed bug #39001 ReflectionProperty returns incorrect declaring class for protected properties). (Tony)
  • Fixed bug #38996 PDO_MYSQL doesn't check connections for liveness). (Tony)
  • Fixed bug #38993 Fixed safe_mode/open_basedir checks for session.save_path, allowing them to account for extra parameters). (Ilia)
  • Fixed bug #38989 Absolute path with slash at beginning doesn't work on win). (Dmitry)
  • Fixed bug #38985 Can't cast COM objects). (Wez)
  • Fixed bug #38981 using FTP URLs in get_headers() causes crash). (Tony)
  • Fixed bug #38963 Fixed a possible open_basedir bypass in tempnam()). (Ilia)
  • Fixed bug #38961 metaphone() results in segmentation fault on NetBSD). (Tony)
  • Fixed bug #38949 Cannot get xmlns value attribute). (Rob)
  • Fixed bug #38942 Double old-style-ctor inheritance). (Dmitry)
  • Fixed bug #38941 imap extension does not compile against new version of the imap library). (Ilia)
  • Fixed bug #38934 move_uploaded_file() cannot read uploaded file outside of open_basedir). (Ilia)
  • Fixed bug #38904 apache2filter changes cwd to /). (Ilia, Hannes)
  • Fixed bug #38891 get_headers() do not work with curl-wrappers). (Ilia)
  • Fixed bug #38882 ldap_connect causes segfault with newer versions of OpenLDAP). (Tony)
  • Fixed bug #38859 parse_url() fails if passing '@' in passwd). (Tony)
  • Fixed bug #38850 lookupNamespaceURI doesn't return default namespace). (Rob)
  • Fixed bug #38844 curl_easy_strerror() is defined only since cURL 7.12.0). (Tony)
  • Fixed bug #38813 DOMEntityReference->__construct crashes when called explicitly). (Rob)
  • Fixed bug #38808 "maybe ref" issue for current() and others). (Dmitry)
  • Fixed bug #38779 engine crashes when require()'ing file with syntax error through userspace stream wrapper). (Tony, Dmitry)
  • Fixed bug #38772 inconsistent overriding of methods in different visibility contexts). (Dmitry)
  • Fixed bug #38759 PDO sqlite2 empty query causes segfault). (Tony)
  • Fixed bug #38721 Invalid memory read in date_parse()). (Tony, Derick)
  • Fixed bug #38700 SoapClient::__getTypes never returns). (Dmitry)
  • Fixed bug #38693 curl_multi_add_handle() set curl handle to null). (Ilia)
  • Fixed bug #38687 sockaddr local storage insufficient for all sock families). (Sara)
  • Fixed bug #38661 mixed-case URL breaks url-wrappers). (Ilia)
  • Fixed bug #38653 memory leak in ReflectionClass::getConstant()). (Tony)
  • Fixed bug #38649 uninit'd optional arg in stream_socket_sendto()). (Sara)
  • Fixed bug #38637 curl_copy_handle() fails to fully copy the cURL handle). (Tony, Ilia)
  • Fixed bug #38624 Strange warning when incrementing an object property and exception is thrown from __get method). (Tony)
  • Fixed bug #38623 leaks in a tricky code with switch() and exceptions). (Dmitry)
  • Fixed bug #38579 include_once() may include the same file twice). (Dmitry)
  • Fixed bug #38574 missing curl constants and improper constant detection). (Ilia)
  • Fixed bug #38543 shutdown_executor() may segfault when memory_limit is too low). (Dmitry)
  • Fixed bug #38535 memory corruption in pdo_pgsql driver on error retrieval inside a failed query executed via query() method). (Ilia)
  • Fixed bug #38534 segfault when calling setlocale() in userspace session handler). (Tony)
  • Fixed bug #38524 strptime() does not initialize the internal date storage structure). (Ilia)
  • Fixed bugs #38511, #38473, #38263 (Fixed session extension request shutdown order to ensure it is shutdown before the extensions it may depend on). (Ilia)
  • Fixed bug #38488 Access to "php://stdin" and family crashes PHP on win32). (Dmitry)
  • Fixed bug #38474 getAttribute select attribute by order, even when prefixed). (Rob)
  • Fixed bug #38467 --enable-versioning causes make fail on OS X). (Tony)
  • Fixed bug #38465 ReflectionParameter fails if default value is an access to self::). (Johannes)
  • Fixed bug #38464 array_count_values() mishandles numeric strings). (Matt Wilmas, Ilia)
  • Fixed bug #38461 setting private attribute with __set() produces segfault). (Tony)
  • Fixed bug #38458 PECL bug #8944, PECL bug #7775 (error retrieving columns after long/text columns with PDO_ODBC). (Wez)
  • Fixed bug #38454 warning upon disabling handler via xml_set_element_handler). (dtorop933 at gmail dot com, Rob)
  • Fixed bug #38451 PDO_MYSQL doesn't compile on Solaris). (Tony)
  • Fixed bug #38450 constructor is not called for classes used in userspace stream wrappers). (Tony)
  • Fixed bug #38438 DOMNodeList->item(0) segfault on empty NodeList). (Ilia)
  • Fixed bug #38431 xmlrpc_get_type() crashes PHP on objects). (Tony)
  • Fixed bug #38427 unicode causes xml_parser to misbehave). (Rob)
  • Fixed bug #38424 Different attribute assignment if new or existing). (Rob)
  • Fixed bug #38400 Use of com.typelib_file may cause a crash). (Ilia)
  • Fixed bug #38394 PDO fails to recover from failed prepared statement execution). (Ilia)
  • Fixed bug #38377 session_destroy() gives warning after session_regenerate_id()). (Ilia)
  • Fixed bug #38357 dbase_open can't open DBase 3 dbf file). (rodrigo at fabricadeideias dot com, Mike)
  • Fixed bug #38354 Unwanted reformatting of XML when using AsXML). (Christian)
  • Fixed bug #38347 Segmentation fault when using foreach with an unknown/empty SimpleXMLElement). (Tony)
  • Fixed bug #38322 reading past array in sscanf() leads to arbitrary code execution). (Tony)
  • Fixed bug #38315 Constructing in the destructor causes weird behavior). (Dmitry)
  • Fixed bug #38303 spl_autoload_register() suppress all errors silently). (Ilia)
  • Fixed bug #38290 configure script ignores --without-cdb,inifile,flatfile). (Marcus)
  • Fixed bug #38289 segfault in session_decode() when _SESSION is NULL). (Tony)
  • Fixed bug #38287 static variables mess up global vars). (Dmitry)
  • Fixed bug #38278 session_cache_expire()'s value does not match phpinfo's session.cache_expire). (Tony)
  • Fixed bug #38276 file_exists() works incorrectly with long filenames on Windows). (Ilia, Tony)
  • Fixed bug #38269 fopen wrapper doesn't fail on invalid hostname with curlwrappers enabled). (Tony)
  • Fixed bug #38265 heap corruption). (Dmitry)
  • Fixed bug #38261 openssl_x509_parse() leaks with invalid cert) (Pierre)
  • Fixed bug #38255 openssl possible leaks while passing keys) (Pierre)
  • Fixed bug #38253 PDO produces segfault with default fetch mode). (Tony)
  • Fixed bug #38251 socket_select() and invalid arguments). (Tony)
  • Fixed bug #38236 Binary data gets corrupted on multipart/formdata POST). (Ilia)
  • Fixed bug #38234 Exception in __clone makes memory leak). (Dmitry, Nuno)
  • Fixed bug #38229 strtotime() does not parse YYYY-MM format). (Ilia)
  • Fixed bug #38224 session extension can't handle broken cookies). (Ilia)
  • Fixed bug #38220 Crash on some object operations). (Dmitry)
  • Fixed bug #38217 ReflectionClass::newInstanceArgs() tries to allocate too much memory). (Tony)
  • Fixed bug #38214 gif interlace output cannot work). (Pierre)
  • Fixed bugs #38213, #37611, #37571 (wddx encoding fails to handle certain characters). (Ilia)
  • Fixed bug #38212 Segfault on invalid imagecreatefromgd2part() parameters). (Pierre)
  • Fixed bug #38211 variable name and cookie name match breaks script execution). (Dmitry)
  • Fixed bug #38199 fclose() unable to close STDOUT and STDERR). (Tony)
  • Fixed bug #38198 possible crash when COM reports an exception). (Ilia)
  • Fixed bug #38194 ReflectionClass::isSubclassOf() returns TRUE for the class itself). (Ilia)
  • Fixed bug #38183 disable_classes=Foobar causes disabled class to be called Foo). (Jani)
  • Fixed bug #38179 imagecopy from a palette to a truecolor image loose alpha channel) (Pierre)
  • Fixed bug #38173 Freeing nested cursors causes OCI8 to segfault). (Tony)
  • Fixed bug #38168 Crash in pdo_pgsql on missing bound parameters). (Ilia)
  • Fixed bug #38161 oci_bind_by_name() returns garbage when Oracle didn't set the variable). (Tony)
  • Fixed bug #38146 Cannot use array returned from foo::__get('bar') in write context). (Dmitry)
  • Fixed bug #38132 ReflectionClass::getStaticProperties() retains ? in key names). (Ilia)
  • Fixed bug #38125 undefined reference to spl_dual_it_free_storage). (Marcus)
  • Fixed bug #38112 corrupted gif segfaults) (Pierre)
  • Fixed bug #38096 large timeout values ignored on 32bit machines in stream_socket_accept() and stream_socket_client()). (Ilia)
  • Fixed bug #38086 stream_copy_to_stream() returns 0 when maxlen is bigger than the actual length). (Tony)
  • Fixed bug #38072 boolean arg for mysqli_autocommit() is always true on Solaris). (Tony)
  • Fixed bug #38067 Parameters are not decoded from utf-8 when using encoding option). (Dmitry)
  • Fixed bug #38064 ignored constructor visibility). (Marcus)
  • Fixed bug #38055 Wrong interpretation of boolean parameters). (Dmitry)
  • Fixed bug #38047 "file" and "line" sometimes not set in backtrace from inside error handler). (Dmitry)
  • Fixed bug #38019 segfault extending mysqli class). (Dmitry)
  • Fixed bug #38005 SoapFault faultstring doesn't follow encoding rules). (Dmitry)
  • Fixed bug #38004 Parameters in SoapServer are decoded twice). (Dmitry)
  • Fixed bug #38003 in classes inherited from MySQLi it's possible to call private constructors from invalid context). (Tony)
  • Fixed bug #37987 invalid return of file_exists() in safe mode). (Ilia)
  • Fixed bug #37947 zend_ptr_stack reallocation problem). (Dmitry)
  • Fixed bug #37945 pathinfo() cannot handle argument with special characters like German "Umlaut"). (Mike)
  • Fixed bug #37931 possible crash in OCI8 after database restart when using persistent connections). (Tony)
  • Fixed bug #37923 Display constant value in reflection::export). (Johannes)
  • Fixed bug #37920 compilation problems on z/OS). (Tony)
  • Fixed bug #37870 pgo_pgsql tries to de-allocate unused statements). (Ilia, ce at netage dot bg)
  • Fixed bug #37864 file_get_contents() leaks on empty file). (Hannes)
  • Fixed bug #37862 Integer pointer comparison to numeric value). (bugs-php at thewrittenword dot com)
  • Fixed bug #37846 wordwrap() wraps incorrectly). (ddk at krasn dot ru, Tony)
  • Fixed bug #37816 ReflectionProperty does not throw exception when accessing protected attribute). (Marcus)
  • Fixed bug #37811 define not using toString on objects). (Marcus)
  • Fixed bug #37807 segmentation fault during SOAP schema import). (Tony)
  • Fixed bug #37806 weird behavior of object type and comparison). (Marcus)
  • Fixed bug #37780 memory leak trying to execute a non existing file (CLI)). (Mike)
  • Fixed bug #37779 empty include_path leads to search for files inside /). (jr at terragate dot net, Ilia)
  • Fixed bug #37747 strtotime segfaults when given "nextyear"). (Derick)
  • Fixed bug #37720 merge_php_config scrambles values). (Mike, pumuckel at metropolis dot de)
  • Fixed bug #37709 Possible crash in PDO::errorCode()). (Ilia)
  • Fixed bug #37707 clone without assigning leaks memory). (Ilia, Nuno, Dmitri)
  • Fixed bug #37705 Semaphore constants not available). (Ilia)
  • Fixed bug #37671 MySQLi extension fails to recognize BIT column). (Ilia)
  • Fixed bug #37667 Object is not added into array returned by __get). (Marcus)
  • Fixed bug #37635 parameter of pcntl signal handler is trashed). (Mike)
  • Fixed bug #37632 Protected method access problem). (Marcus)
  • Fixed bug #37630 MySQL extensions should link against thread safe client libs if built with ZTS). (Mike)
  • Fixed bug #37620 mysqli_ssl_set validation is inappropriate). (Georg)
  • Fixed bug #37616 DATE_RFC822 does not product RFC 822 dates). (Hannes Magnusson, Derick)
  • Fixed bug #37614 Class name lowercased in error message). (Johannes)
  • Fixed bug #37587 var without attribute causes segfault). (Marcus)
  • Fixed bug #37586 Bumped minimum PCRE version to 6.6, needed for recursion limit support). (Ilia)
  • Fixed bug #37581 oci_bind_array_by_name clobbers input array when using SQLT_AFC, AVC). (Tony)
  • Fixed bug #37569 WDDX incorrectly encodes high-ascii characters). (Ilia)
  • Fixed bug #37565 Using reflection::export with simplexml causing a crash). (Marcus)
  • Fixed bug #37564 AES privacy encryption not possible due to net-snmp 5.2 compatibility issue). (Jani, patch by scott dot moynes+php at gmail dot com)
  • Fixed bug #37563 array_key_exists performance is poor for &$array). (Ilia)
  • Fixed bug #37558 timeout functionality doesn't work after a second PHP start-up on the same thread). (p dot desarnaud at wanadoo dot fr)
  • Fixed bug #37531 oci8 persistent connection corruption). (Tony)
  • Fixed bug #37523 namespaces added too late, leads to missing xsi:type attributes. incompatibility with libxml2-2.6.24). (Dmitry)
  • Fixed bug #37514 strtotime doesn't assume year correctly). (Derick)
  • Fixed bug #37510 session_regenerate_id changes session_id() even on failure). (Hannes)
  • Fixed bug #37505 touch() truncates large files). (Ilia)
  • Fixed bug #37499 CLI segmentation faults during cleanup with sybase-ct extension enabled). (Tony)
  • Fixed bug #37496 FastCGI output buffer overrun). (Piotr, Dmitry)
  • Fixed bug #37487 oci_fetch_array() array-type should always default to OCI_BOTH). (Tony)
  • Fixed bug #37457 Crash when an exception is thrown in accept() method of FilterIterator). (Marcus)
  • Fixed bug #37456 DOMElement->setAttribute() loops forever). (Rob)
  • Fixed bug #37445 Fixed crash in pdo_mysql resulting from premature object destruction). (Ilia)
  • Fixed bug #37428 PHP crashes on windows if there are start-up errors and event log is used for logging them). (Edin)
  • Fixed bug #37418 tidy module crashes on shutdown). (Tony)
  • Fixed bug #37416 iterator_to_array() hides exceptions thrown in rewind() method). (Tony)
  • Fixed bug #37413 Rejected versions of flex that don't work). (Ilia)
  • Fixed bug #37395 recursive mkdir() fails to create nonexistent directories in root dir). (Tony)
  • Fixed bug #37394 substr_compare() returns an error when offset equals string length). (Ilia)
  • Fixed bug #37392 Unnecessary call to OCITransRollback() at the end of request). (Tony)
  • Fixed bug #37376 fastcgi.c compile fail with gcc 2.95.4). (Ilia)
  • Fixed bug #37368 Incorrect timestamp returned for strtotime()). (Derick)
  • Fixed bug #37363 PDO_MYSQL does not build if no other mysql extension is enabled). (Mike)
  • Fixed bug #37348 make PEAR install ignore open_basedir). (Ilia)
  • Fixed bug #37341 $_SERVER in included file is shortened to two entries, if $_ENV gets used). (Dmitry)
  • Fixed bug #37313 sigemptyset() used without including <signal.h>). (jdolecek)
  • Fixed bug #37306 max_execution_time = max_input_time). (Dmitry)
  • Fixed bug #37278 SOAP not respecting uri in __soapCall). (Dmitry)
  • Fixed bug #37265 Added missing safe_mode & open_basedir checks to imap_body()). (Ilia)
  • Fixed bug #37262 var_export() does not escape ? character). (Ilia)
  • Fixed bug #37256 php-fastcgi doesn't handle connection abort). (Dmitry)
  • Fixed bug #37244 Added strict flag to base64_decode() that enforces RFC3548 compliance). (Ilia)
  • Fixed bug #37144 PHP crashes trying to assign into property of dead object). (Dmitry)
  • Fixed bug #36949 invalid internal mysqli objects dtor). (Mike)
  • Fixed bug #36732 req/x509 extensions support for openssl_csr_new and openssl_csr_sign) (ben at psc dot edu, Pierre)
  • Fixed bug #36759 Objects destructors are invoked in wrong order when script is finished). (Dmitry)
  • Fixed bug #36681 pdo_pgsql driver incorrectly ignored some errors). (Wez, Ilia)
  • Fixed bug #36630 umask not reset at the end of the request). (Ilia)
  • Fixed bug #36515 Unlinking buckets from non-existent brigades). (Sara)
  • Fixed bug #35973 Error ORA-24806 occurs when trying to fetch a NCLOB field). (Tony)
  • Fixed bug #35886 file_get_contents() fails with some combinations of offset & maxlen). (Nuno)
  • Fixed bug #35512 Lack of read permission on main script results in E_WARNING rather then E_ERROR). (Ilia)
  • Fixed bug #34180 --with-curlwrappers causes PHP to disregard some HTTP stream context options). (Mike)
  • Fixed bug #34066 recursive array_walk causes segfault). (Tony)
  • Fixed bug #34065 throw in foreach causes memory leaks). (Dmitry)
  • Fixed bug #34005 oci_password_change() fails). (pholdaway at technocom-wireless dot com, Tony)
  • Fixed bug #33895 Missing math constants). (Hannes)
  • Fixed bug #33770 https:// or ftps:// do not work when --with-curlwrappers is used and ssl certificate is not verifiable). (Ilia)
  • Fixed bug #29538 number_format and problem with 0). (Matt Wilmas)
  • Fixed bug #28382 openssl_x509_parse() extensions support) (Pierre)
  • Fixed PECL bug #9061 (oci8 might reuse wrong persistent connection). (Tony)
  • Fixed PECL bug #8816 (issue in php_oci_statement_fetch with more than one piecewise column) (jeff at badtz-maru dot com, Tony)
  • Fixed PECL bug #8112 (OCI8 persistent connections misbehave when Apache process times out). (Tony)
  • Fixed PECL bug #7755 (error selecting DOUBLE fields with PDO_ODBC). ("slaws", Wez)
Read full post »

การเปรียบเทียบค่าของ ตัวแปล php โดยใช้ function

0 ความคิดเห็น
การเปรียบเทียบ ค่าของ $x โดยใช้ function ต่างๆ ดังนี้
if($x)
ค่าของ x gettype() empty() is_null() isset() boolean
$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
$x = -1; integer FALSE FALSE TRUE TRUE
$x = "1"; string FALSE FALSE TRUE TRUE
$x = "0"; string TRUE FALSE TRUE FALSE
$x = "-1"; string FALSE FALSE TRUE TRUE
$x = "php"; string FALSE FALSE TRUE TRUE
$x = "TRUE"; string FALSE FALSE TRUE TRUE
$x = "false"; string FALSE FALSE TRUE TRUE

ที่มา php.net
Read full post »

mysql_insert_id BIGINT OS 64 bit โปรดระวัง

0 ความคิดเห็น
การใช้ฟังก์ชั่น mysql_insert_id()? กับ DataType BIGINT? บนOS 64บิท โดยระวัง
ฟังก์ชั่นนี้ mysql_insert_id() อาจทำให้เกิดข้อผิดพลาดขึ้นมาได้
ถ้าต้องการค่า AUTO_INCREMENT จากการเพิ่้มข้อมูลครั้งล่าสุดลงในตารางที่ได้กำหนด field เป็น AUTO_INCREMENT จากตารางในฐานข้อมูลที่อยู่ในสภาพแวดล้อม ดังกล่าว แนะนำให้ใช้ ฟังก์ชั่นของ Mysql SQL function LAST_INSERT_ID() รันเพื่อเอาผลมาแทน

$q = "SELECT LAST_INSERT_ID() FROM $table";
return
mysql_num_rows(mysql_query($q)) + 1;
Read full post »

การเปรียบเทียบประสิทธิภาพ ของประภาษาโปรแกรม php ruby python ปี 2017

0 ความคิดเห็น

Performance Comparison PHP vs Ruby vs Python

           ปัจจุบันเทคโนยีได้มีการพัฒนาอย่างต่อเนื่อง อย่างเช่นสังคมออนไลน์ที่เป็นช่องทางในการติดต่อสื่อ รวมรวมข้อมูล แสดงข้อมูล เป็นจุดประสงค์ของผู้พัฒนาและผู้ที่ให้บริการ หรือเรียกง่ายๆ เป็นโลกของข้อมูล โดยข้อมูลเหล่านี้จะไม่สามารถมองเห็นได้ด้วยตาเปล่า แต่ข้อมูลเหล่านี้ทำให้ยุคสมัยได้เปรียนแปลงไปในทางที่ดี มีความทันสมัยมากยิ่งขึ้น
           หลายๆธรุกิจใช้ผลประโยชน์เหล่านี้เพื่มการเติมโตของธุรกิจ ใช้ช่องทางออนไลน์เป็นสื่อกลางเช่น เว็บไซต์ โซเชียล Search Engine เพื่อนำเสนอให้เป้าหมายได้รู้ถึงจุดประสงคหลักของธุรกิจ เว็บไซต์เริ่มเข้ามามีบทบาทอย่างมากในการดำเนินธุรกิจ และดำเนินชีวิตประจำวัน เว็บไซต์เป็นเหมือนอีกหนึ่งโลกที่ทุกคนสามารถรับรู้สิ่งต่างๆได้ผ่านเว็บไซต์
            และเว็บไซต์ไม่ใช้ใครก็สามารถสร้างขึ้นมาได้การทำเว็บไซต์ที่ดีจะต้องมีหลักการหลายๆอย่างเข้ามาเกี่ยวข้องเพื่อให้เว็บไซต์มีผู้เข้าชม และสิ่งที่สำคัญคือ ผู้พัฒนาเว็บไซต์ หรือ โปรแกรเมอร์ ที่ทำหน้าที่เขียนคำสั่งต่างๆให้ เว็บไซต์สามารถทำงานได้ตรงตามที่ต้องการ และที่กล่าวไว้ข้างต้น ปัจจุบันโลกได้เข้าสู่เทคโนโลยีแบบเต็มตัวการแข่งขันจึงมีมากขึ้น สำหรับผู้พัฒนาก็เช่นเดียวกัน ในการเขียนเว็บไซต์จะมีภาษาโปรแกรมมากมายที่เลือกใช้ แต่ละภาษาก็จะมีข้อดี ข้อเสียแตกต่างกัน แต่ที่สำคัญคือความรวดเร็วในการพัฒนาและควายง่ายของภาษาในการพัฒนาต่อๆไป
            ภาษาที่มีความเร็วในการประมวลผลมากที่สุดคือ PHP  จากตารางด้านล่าง
การเปรียบเทียบประสิทธิภาพ
การเปรียบเทียบประสิทธิภาพ
                    ภาษาที่มีความเร็วในการประมวลผลมากที่สุดคือ php ซึ่งได้การตอบรับอย่างมากจากโปรแกรมเมอร์ทั่วโลก เป็นภาษาที่เหมาะกับการออกแบบเว็บไซต์อย่างมาก และความอยากของโค้ดอยู่ในระดับที่ไม่ยากมาก สำหรับโปรแกรมเมอร์รุ่นใหม่ๆก็ศึกษาและทำความเข้าใจได้ง่าย มีข้อมูลมากมายให้ศึกษา ต่อมาจะเป็นภาษา Ruby ภาษา ruby ถือว่าเป็นภาษาที่ค่อนข้างมาแรงเพราะว่าจุดเด่นของ ruby จะเป็นรูปแบบการเขียนที่ง่ายมากและมีความเร็วในการประมวลผลที่เร็วพอสมควร ทำให้ผู้พัฒนาหลายๆคนสนใจมาประกอบธุรกิจ ภาษา Python เป็นภาษาที่มีความเร็วในการประมวลผลช้าที่สุด แต่ไม่ใช่ว่าไม่ดี แต่ด้วยการทำงานที่แตกต่างและการทำงานในส่วนอื่นๆได้ดีกว่า และภาษา python เป็นภาษาที่เขียนง่าย
Read full post »

แก้ไขปัญหาการแสดงผลเพจปลั๊กอินเฟสบุ๊คไม่แสดง

0 ความคิดเห็น

การตั้งค่าเพจปลั๊กอินเฟสบุ๊คไม่แสดงผล

การตั้งค่าเพจปลั๊กอิน
การตั้งค่าเพจปลั๊กอิน

         Facebook (เฟสบุ๊ค) เป็นโซเชียลบนเว็บไซต์ซึ่งเฟสบุ๊คจะมีส่วนเสริมต่างๆมากมายที่ให้นักพัฒนานำไปใช้ยังเว็บไซต์ตัวเองเช่น ปลั๊กอินปุ่มถูกใจ ปุ่มแชร์ ปลั๊กอินเพจเฟสบุ๊ค ซึ่งทาง Developers.facebook ได้นำให้ทางเว็บไซต์ได้นำไปใช้งานในรูปแบบของ JavaScript SDK, IFrame, หรือ HTML เพียงแค่คัดลอกไปวางที่เว็บไซต์ก็ได้ปลั๊กอินเฟสบุ๊คไปแสดงที่หน้าเว็บไซต์ของตัวเองแล้ว
ตัวอย่างปัญหาการไม่แสดงผล : http://www.mindphp.com/forums/viewtopic.php?f=20&p=109113#p109113
Facebook for Developers : https://developers.facebook.com/docs/plugins/page-plugin
          สำหรับวันนี้จะมาพูดถึง เพจปลั๊กอินเฟสบุ๊ค ที่หลายๆคนใช้งานกันและยังมีหลายคนที่ยังติดปัญหาในการใช้งานปลั๊กอินนี้อยู่ การแก้ไขปัญหาการแสดงผลเพจเฟสบุ๊คไม่แสดง

1. กำหนด URL Facebook แล้ว แต่หน้าเพจไม่แสดงด้านล่าง

เพจปลั๊กอินไม่แสดงผล
เพจปลั๊กอินไม่แสดงผล

2. ผู้ใช้ที่เป็นเจ้าของเพจต้องเข้าไปตั้งค่าที่หน้าเพจโดยเลือก

  • การตั้งค่า > ทั่วไป
  • การจำกัดประเทศ : ซ่อนเพจนี้จากผู้ชมในประเทศเหล่านี้
  • การจำกัดอายุ : กำให้ชมได้ทุกคนหรือทุกคน (13+)
การตั้งค่าเพจปลั๊กอินที่หน้า Facebook
การตั้งค่าเพจปลั๊กอินที่หน้า Facebook

1. ตัวอย่างการแสดงผลเพจปลั๊กอินจะแสดง ตอนนี้สามารถนำไปใช้งานได้แล้ว

เพจปลั๊กอินไม่แสดงผล
เพจปลั๊กอินไม่แสดงผล
Read full post »

การคำนวณมูลค่าของเงินในปัจจุบันหรือเงินต้น (PV: Present Value)

0 ความคิดเห็น

การคำนวณมูลค่าของเงินในปัจจุบันหรือเงินต้น (PV: Present Value)


          PV: Persent Value เป็นการคำนวณมูลค่าเงินในปัจจุบันหรือเงินต้นโดยมีสูตรที่ใช้ในการคำนวณมือดังรูป
PV เป็นการคำนวณมูลค่าเงินในปัจจุบันหรือเงินต้น
สูตรคำนวณ PV แบบคำนวณมือ
          คำอธิบายสูตร
                    rate     อัตราดอกเบี้ย
                    nper     งวดเวลา
                    pmt     เงินที่จ่ายแต่ละงวด
                    pv       ค่าเงินในอนาคต
                    type    จ่ายเงินทุกสิ้นเดือนมีค่าเป็น 0 จ่ายเงินทุกต้นเดือนมีค่าเป็น 1
                    pv       ค่าเงินในปัจจุบัน

ตัวอย่างโจทย์
          ในอนาคตมานีต้องการเงินจำนวน 20,000 บาท จึงนำเงินไปฝากกับธนาคาร โดยธนาคารให้ดอกเบี้ย 5% ต่อปี โดยจะฝากเงินทุกๆต้นปี ปีละ 1,000 บาท เป็นเวลา 3 ปี อยากทราบว่ามานีต้องนำเงินไปฝากธนาคารก้อนแรกเป็นเงินจำนวนเท่าใหร่
วิธีทำ
          กำหนดให้
                    ate = 0.05 (ได้มาจาก 5/100 = 0.05)
                    nper = 3
                   pmt = 1000
                    pv = 20000
                    type = 1
                    pv = ?

วิธีการคำนวณมือ
PV เป็นการคำนวณมูลค่าเงินในปัจจุบันหรือเงินต้น
คำนวนมูลค่าเงินในปัจจุบันแบบคำนวณมือ

           ในการคำนวณมูลค่าเงินในปัจจุบันหรือเงินต้นเหมาะกับการใช้หามูลค่าเงินในปัจจุบันที่ต้องการในกรณีที่รู้มูลค่าเงินในอนาคตอยู่แล้วเช่นนำไปหากรณีที่ต้องการฝากเงินให้ได้มูลค่าเงินในอนาคตที่ต้องการแล้วหาว่ามูลค่าเงินในปัจจุบันเราต้องฝากเงินเท่าไหร่ถึงจะได้เงินในอนาคตที่เราตั้งไว้
Read full post »

วันอังคารที่ 28 มกราคม พ.ศ. 2563

ความแตกต่างระหว่าง var_dump var_export และ print_r

0 ความคิดเห็น
ใน php programming มีฟังก์ชันมากมายที่ทำหน้าที่แสดงได้ผลลัพ์เพื่อช่วยในการ Debug code   แต่หลายๆอาจจะยังสับสนกับฟังก์ชั่น  var_dump() var_export()และ print_r() ว่ามีความแตกต่างกันอย่างไรและควรใช้ฟังชันไหนดีเพราะว่าฟังก์ชันเหล่านี้ล้วนสามารถแสดงข้อมูลใน Array ได้ทั้งนั้น บทความเราจะมาอธิบายให้เข้าใจกันพร้อมตัวอย่างน่ะครับ
 ฟังก์ชั่น var_dump(), var_export() และ print_r() ของ PHP ทำหน้าที่หลักที่สำคัญเหมือนๆกันคือ การดูค่าของตัวแปร ซึ่งแต่ละฟังก์ชั่นจะมีข้อแตกต่างกันเล็กน้อยครับ
ตัวอย่างเรามี Array ชุดหนึ่ง ซึ่งมีคีย์และค่าที่แตกต่างกันไปดังนี้
$array = array(0,1 => 'one',array(2 => 'two'),3 => true);

สำหรับ ฟังก์ชั่น print_r() โดยทั่วไปจะใช้ประโยชน์ในการ debug โดยตรง เนื่องจากมันทำหน้าที่ ในการแสดงค่าของตัวแปรเท่านั้น ซึ่งมันสามารถแสดงค่าของตัวแปรได้ทุกชนิด  และผลลัพธ์การทำงาน print_r($array); ดังนี้
ผลลัพธ์ ฟังก์ชั่น print_r($array);
Array
(
    [0] => 0
    [1] => one
    [2] => Array
        (
            [2] => two
        )
    [3] => 1
)

ฟังก์ชั่น var_dump() ทำหน้าที่เหมือนกับ print_r() ทุกประการ แต่ฟังก์ชั่นนี้ สามารถแสดงชนิดของตัวแปร(datatype)ได้ด้วยน่ะครับ ผลลัพธ์จะเป็นดังนี้
ผลลัพธ์ ฟังก์ชั่น var_dump($array);
array (size=4)
    0 => int 0
    1 => string 'one' (length=3)
    2 =>
        array (size=1)
            2 => string 'two' (length=3)
    3 => boolean true

และฟังก์ชั่น var_export() ปกติแล้วจะทำหน้าที่เหมือนกับ print_r() ทุกประการ ถ้าไม่ได้กำหนดค่าตัวแปรที่ 2 (หรือกำหนดเป็น false) var_export($array, false); หรือ var_export($array);  ซึ่งผลลัพธ์จะเป็นดังนี้
ผลลัพธ์ ฟังก์ชั่น var_export($array) หรือ var_export($array,false);
​array (
    0 => 0,
    1 => 'one',
    2 =>
        array (
            2 => 'two',
        ),
    3 => true,
)
แต่หากมีการกำหนดค่าตัวแปรที่ 2 เป็น true มันจะส่งออกผลลัพท์เป็น string แทนที่การแสดงค่าของตัวแปรซึ่งเราสามารถนำค่าได้ไปใช้โดยฟังก์ชั่นอื่นต่อได้
จะเห็นได้ว่าแต่ละฟังก์ชันมีความแตกในบางส่วน ขึ้นอยู่กับว่าเราต้องการดูหรือหรับข้อมูลเป็นอย่างไร  ฟังก์ชันเหล่าสามารถช่วยในการ debug code ได้ เพื่อดูข้อมูลหรือลัพธ์ที่ได้เป็นอย่างไหร่
Read full post »

เรียงลำดับวันที่ในอาร์เรย์โดยใช้ PHP

0 ความคิดเห็น
เราได้รับอาร์เรย์มา ซึ่งประกอบด้วยวันที่ หลายๆวันที่ ในรูปแบบ (Y-m-d) และเราต้องเขียนโปรแกรมใน PHP เพื่อเรียงลำดับวันที่ทั้งหมดที่อยู่ในอาร์เรย์จากมากไปน้อย 
ตัวอย่าง input และ output
Input : array("2018-06-04", "2014-06-08", "2018-06-05")
Output : 2018-06-05  2018-06-04  2014-06-08

Input : array("2016-09-12", "2009-09-08", "2009-09-09")
Output : 2016-09-12  2009-09-09  2009-09-08
เพื่อแก้ปัญหานี้ในC / C++ / Java หรือภาษาโปรแกรมอื่น ๆ เราจะต้องเปรียบเทียบวันที่ตามปีเดือนและสุดท้ายตามวันโดยเก็บไว้ในโครงสร้างใด ๆ หรือโครงสร้างข้อมูลที่ต้องการอื่น ๆ แต่ใน PHP  ปัญหานี้ดูเหมือนจะง่ายมากถ้าเราใช้ฟังก์ชั่น strtotime ()    ฟังก์ชั่น strtotime()  เป็นฟังก์ชั่น PHP ที่ใช้เปลี่ยนวันที่ที่กำหนดในรูปแบบใด ๆ ที่เป็น  timestamp  ซึ่งเป็นจำนวนเต็มขนาดใหญ่ integer โดยปกติแล้วติแล้วในการเรียงลำดับอาร์เรย์เราสามารถใช้ ฟังก์ชั่น usort()  โดยการกำหนดฟังก์ชั่นเปรียบเทียบ ฟังก์ชันตัวเปรียบเทียบจะยอมรับอาร์กิวเมนต์ของวันที่ สองค่าซึ่งจะถูกแปลงเป็นเวลาจำนวนเต็มโดยใช้ฟังก์ชั่น strtotime () จากนั้นเปรียบเทียบกับวันที่จัดเรียงตาม  timestamp พอจะเข้าใจหลักการแล้วใช่ไหมครับ เรามาดูกัน
ฟังก์ชั่น Inbuilt ที่ใช้:
  •  strtotime(): ฟังก์ชันนี้เปลี่ยนสตริงวันที่ที่กำหนดเป็น timestamp (ค่า integer )
  • usort(): ฟังก์ชั่นนี้จะเรียงลำดับอาร์เรย์ที่กำหนดตามฟังก์ชั่นการเปรียบเทียบที่กำหนด

ตัวอย่างโค้ดดังนี้
<?php 
// PHP program to sort array of dates 

// user-defined comparison function 
// based on timestamp 
function compareByTimeStamp($time1, $time2) 
{ 
 if (strtotime($time1) < strtotime($time2)) 
  return 1; 
 else if (strtotime($time1) > strtotime($time2)) 
  return -1; 
 else
  return 0; 
} 

// Input Array 
$arr = array("2016-09-12", "2009-09-06", "2009-09-09"); 

// sort array with given user-defined function 
usort($arr, "compareByTimeStamp"); 

print_r($arr); 

?> 
ผลลัพธ์ที่ได้
Array 
( 
    [0] => 2016-09-12 
    [1] => 2009-09-09 
    [2] => 2009-09-06 
)
ผลลัพธ์ที่ก็เป็น array ที่วันที่ถูกเรียงจากมากไปน้อย หรือ ล่าสุดไปอดีตเรียบร้อย  ซึ่งหลักๆเราใช้แค่สองฟังก์ชันนั้นคือ strtotime() และ usort() หวังว่าผู้อ่านจะเข้าใจและสามารถนำไปต่อยอดได้น่ะครับ
Read full post »

การรัน JavaScript ใน PHP

0 ความคิดเห็น

JavaScript เป็นภาษาสคริปต์ฝั่งไคลเอ็นต์และ PHP  เป็นภาษาสคริปต์ฝั่งเซิร์ฟเวอร์     ซึ่งปกติ JavaScript ใช้เป็นฝั่งไคลเอ็นต์เพื่อตรวจสอบและตรวจสอบรายละเอียดไคลเอ็นต์และ PHP เป็นฝั่งเซิร์ฟเวอร์ที่ใช้ในการโต้ตอบกับฐานข้อมูลโดยใน PHP จะใช้ HTML เป็นสตริงในโค้ด เพื่อที่จะแสดงให้เบราว์เซอร์เราสามารถสร้างโค้ด JavaScript ที่เป็นสตริงของโค้ด PHP ได้ ดังนี้ฃ
ตัวอย่างโค้ด 
<?php 
echo '<script type="text/JavaScript"> 
 prompt("mindphp"); 
 </script>' 
; 
?> 
ผลลัพธ์ที่จะได้คือ
run JavaScript from PHP
JavaScript promt
ตัวอย่างที่สองเรามาลองดู alert กัน ซึ่งสามารถใส่ โค้ด javascript นอกแท็ก php ดังนี้
<?php 
 // some php stuff 
?> 
<script type="text/javascript"> 
 alert('Mindphp'); 
</script> 
ผลลัพธ์ที่ได้ 
JavaScript code outside of PHP code
่javascript ด้านนอกของ php แต่ในไฟล์เดียวกัน
จากตัวอย่างเราจะเห็นเราสามารถเขียนโค้ด javascript ใน php ได้ ซึ่งมีสองรูปแบบ คือ ใช้ php echo สติงที่เป็นโค้ด javascript เลยยแต่ถ้าโค้ดjavascript ที่มันยาวไปอาจจะไม่เหมาะ  และรูปแบบที่สองคือ เขียนโค้ด javascript ด้านนอกของแท็กเปิดปิด php  ซึ่งสามารถใช้ได้เช่นกัน
Read full post »

วันจันทร์ที่ 13 มกราคม พ.ศ. 2563

การแปลงข้อมูลที่ดึงมาจาก database ที่เป็น list ให้เป็น string เพื่อนำมาใช้ประโยชน์ในด้านต่างๆ

0 ความคิดเห็น
วันนี้ผมจะมาแนะนำวิธีการนำข้อมูลที่เรา SELECT มาจาก database เพื่อนำมาใช้ประโยชน์ในด้านต่างๆ ด้วยภาษา Python อย่างวันนี้ตัวอย่างที่ยกขึ้นมา จะเป็นการนำ ข้อมูล Version ที่อยู่ใน database มา + กันและแสดงผลลัพธ์ค่าที่เราต้องการนั่นเอง เพื่อไม่ให้เสียเวลาเรามาเริ่มกันเลย

1.ทำการ import library psycopg2 เพื่อที่จะทำการเชื่อมต่อกับ database
Code: Select all
import psycopg2 as p
2.เขียนคำสั่งเพื่อเชื่อมต่อ database
Code: Select all
con = p.connect(
    host='localhost',
    database='ben01',
    user='postgres',
    password='postgres'
)
3. สร้างฟังก์ชั่นขึ้นมาเพื่อที่เราจะสามารถทำการเรียกข้อมูลจาก database มาใช้
Code: Select all
def sum_ver():
    cur = con.cursor()
    cur.execute("SELECT latest_version FROM ir_module_module where state = 'installed'")
    total = cur.fetchall()
4. สร้างตัวแปรขึ้นมาเพื่อที่จะเก็บค่าตัวเลขที่เราจะทำการแยกเอาไว้
Code: Select all
    num1 = 0
    num2 = 0
    num3 = 0
    num4 = 0
    num5 = 0
โดย code คือ เราต้องการจะแสดงข้อมูลของ lastest_version จาก ฐานข้อมูล ir_module_module โดยที่ข้อมูลที่เราต้องการจะโชวน์ state จะต้องเป็น installed เท่านั้นถ้า ไม่ใช่ จะไม่ทำการเรียกของแถวนั้นมาโชวน์
ผลลัพท์
Python Knowledge-1.png
Python Knowledge-1.png (3.25 KiB) Viewed 10 times
5. ค่าที่ได้จะเป็น ประเภท list ซึ่งถ้าเราต้องการจะนำเลขภายในมาใช้เราจะต้องทำการดึง ตัวเลขภายในออกมาให้กลายเป็น string ก่อน โดยวิธีการคือเราจะใช้ for loop ในการดึงค่า
Code: Select all
    for row in total:
        for i in row:
ผลลัพธ์
Python Knowledge-1.png
Python Knowledge-1.png (2.02 KiB) Viewed 10 times
6. ซึ่งพอถึงขั้นตอนนี้แล้วเราจะทำการแยกค่าภายในตัว string เพื่อเก็บไว้ภายในตัวแปรที่เราทำการสร้างขึ้น โดยใช้คำสั่ง split
Code: Select all
            sp = i.split('.')
แต่ภายในข้อมูลของเราบางตัวมันเป็นค่า 4 ตำแหน่ง บางตัวเป็น 5 ตำแหน่ง ซึ่งเราจะใช้ 5 ตำแหน่ง
Python Knowledge-1.png
Python Knowledge-1.png (2.01 KiB) Viewed 10 times
7. เราสามารถแก้ไขได้ง่ายๆโดยการ ใช้ append เพื่อเพิ่ม 0 ต่อไปข้างหลังทุกตัว
Code: Select all
sp.append('0')
8. เราจะทำการนำค่าที่เรา split แล้ว มาทำการ + เพิ่มภายในตัวแปรที่เราได้สร้างขึ้นมาไว้ แต่ละตำแหน่งโดยใช้คำสั่ง
Code: Select all
            num1 += int(sp[0])
            num2 += int(sp[1])
            num3 += int(sp[2])
            num4 += int(sp[3])
            num5 += int(sp[4])
    resu = "Summery Version = {}.{}.{}.{}.{}".format(num1, num2, num3, num4, num5)
    print(resu)
และแสดงผลลัพธ์ที่เราต้องการ
ผลลัพธ์ที่ได้
Python Knowledge-1.png
Python Knowledge-1.png (6.23 KiB) Viewed 10 times
fullcode
Code: Select all
# -*- coding:utf-8 -*
import psycopg2 as p

con = p.connect(
    host='localhost',
    database='ben01',
    user='postgres',
    password='postgres'
)


def sum_ver():
    cur = con.cursor()
    cur.execute("SELECT latest_version FROM ir_module_module where state = 'installed'")
    total = cur.fetchall()
    num1 = 0
    num2 = 0
    num3 = 0
    num4 = 0
    num5 = 0

    for row in total:
        for i in row:
            sp = i.split('.')
            sp.append('0')
            num1 += int(sp[0])
            num2 += int(sp[1])
            num3 += int(sp[2])
            num4 += int(sp[3])
            num5 += int(sp[4])
    resu = "Summery Version = {}.{}.{}.{}.{}".format(num1, num2, num3, num4, num5)
    print(resu)
    
    if __name__ == '__main__':
    sum_ver()
อ้างอิง
viewtopic.php?f=16&t=64136
https://www.w3schools.com/python/ref_string_split.asp
https://www.pythonforbeginners.com/dictionary/python-split
Read full post »

Google Earth คืออะไร กูเกิล เอิร์ธ คือ โปรแกรมสำหรับดูภาพถ่ายทางอากาศ และแผนที่ ทั่วโลก

0 ความคิดเห็น
Google Earth คืออะไร
Google Earth คือ โปรแกรมที่สร้างโดยบริษัท Google ใช้สำหรับดูภาพถ่ายทางอากาศพร้อมทั้งแผนที่ เส้นทาง และผังเมือง รวมทั้งระบบ จีไอเอส ในรูปแบบ 3 มิติ โปรแกรมนี้ช่วยให้เราศึกษาข้อมูลก่อนเดินทางได้เป็นอย่างดี ทำให้เราสามารถค้นหาที่ตั้งของสถานที่ที่เราจะเดินทางไป เส้นทางต่าง ๆ ของเมืองที่เราจะเดินทางไป รวมถึงแหล่งข้อมูลอื่น ๆ เช่น สภาพดินฟ้าอากาศ สำหรับรูปแบบการทำงานของ Google Earth นั้นก็จะเป็นการทำงานแบบ Client Server โปรแกรมส่วนที่พวกเราใช้งานจะเรียกว่า Google Earth client ซึ่ง Google ให้เรามาใช้งานฟรี
Google Earth คืออะไร กูเกิล เอิร์ธ คือ โปรแกรมสำหรับดูภาพถ่ายทางอากาศจากทั่วโลก พร้อมแผนที่ ทั้งดูภาพสถานที่ต่างๆในโลกแบบ 3 มิติได้อีกด้วย

ข้อมูลอ้างอิง
http://th.wikipedia.org
http://www.vcharkarn.com
Read full post »

การแปลงข้อมูลที่ดึงมาจาก database ที่เป็น list ให้เป็น string เพื่อนำมาใช้ประโยชน์ในด้านต่างๆ

0 ความคิดเห็น
วันนี้ผมจะมาแนะนำวิธีการนำข้อมูลที่เรา SELECT มาจาก database เพื่อนำมาใช้ประโยชน์ในด้านต่างๆ ด้วยภาษา Python อย่างวันนี้ตัวอย่างที่ยกขึ้นมา จะเป็นการนำ ข้อมูล Version ที่อยู่ใน database มา + กันและแสดงผลลัพธ์ค่าที่เราต้องการนั่นเอง เพื่อไม่ให้เสียเวลาเรามาเริ่มกันเลย

1.ทำการ import library psycopg2 เพื่อที่จะทำการเชื่อมต่อกับ database
Code: Select all
import psycopg2 as p
2.เขียนคำสั่งเพื่อเชื่อมต่อ database
Code: Select all
con = p.connect(
    host='localhost',
    database='ben01',
    user='postgres',
    password='postgres'
)
3. สร้างฟังก์ชั่นขึ้นมาเพื่อที่เราจะสามารถทำการเรียกข้อมูลจาก database มาใช้
Code: Select all
def sum_ver():
    cur = con.cursor()
    cur.execute("SELECT latest_version FROM ir_module_module where state = 'installed'")
    total = cur.fetchall()
4. สร้างตัวแปรขึ้นมาเพื่อที่จะเก็บค่าตัวเลขที่เราจะทำการแยกเอาไว้
Code: Select all
    num1 = 0
    num2 = 0
    num3 = 0
    num4 = 0
    num5 = 0
โดย code คือ เราต้องการจะแสดงข้อมูลของ lastest_version จาก ฐานข้อมูล ir_module_module โดยที่ข้อมูลที่เราต้องการจะโชวน์ state จะต้องเป็น installed เท่านั้นถ้า ไม่ใช่ จะไม่ทำการเรียกของแถวนั้นมาโชวน์
ผลลัพท์
Python Knowledge-1.png
Python Knowledge-1.png (3.25 KiB) Viewed 9 times
5. ค่าที่ได้จะเป็น ประเภท list ซึ่งถ้าเราต้องการจะนำเลขภายในมาใช้เราจะต้องทำการดึง ตัวเลขภายในออกมาให้กลายเป็น string ก่อน โดยวิธีการคือเราจะใช้ for loop ในการดึงค่า
Code: Select all
    for row in total:
        for i in row:
ผลลัพธ์
Python Knowledge-1.png
Python Knowledge-1.png (2.02 KiB) Viewed 9 times
6. ซึ่งพอถึงขั้นตอนนี้แล้วเราจะทำการแยกค่าภายในตัว string เพื่อเก็บไว้ภายในตัวแปรที่เราทำการสร้างขึ้น โดยใช้คำสั่ง split
Code: Select all
            sp = i.split('.')
แต่ภายในข้อมูลของเราบางตัวมันเป็นค่า 4 ตำแหน่ง บางตัวเป็น 5 ตำแหน่ง ซึ่งเราจะใช้ 5 ตำแหน่ง
Python Knowledge-1.png
Python Knowledge-1.png (2.01 KiB) Viewed 9 times
7. เราสามารถแก้ไขได้ง่ายๆโดยการ ใช้ append เพื่อเพิ่ม 0 ต่อไปข้างหลังทุกตัว
Code: Select all
sp.append('0')
8. เราจะทำการนำค่าที่เรา split แล้ว มาทำการ + เพิ่มภายในตัวแปรที่เราได้สร้างขึ้นมาไว้ แต่ละตำแหน่งโดยใช้คำสั่ง
Code: Select all
            num1 += int(sp[0])
            num2 += int(sp[1])
            num3 += int(sp[2])
            num4 += int(sp[3])
            num5 += int(sp[4])
    resu = "Summery Version = {}.{}.{}.{}.{}".format(num1, num2, num3, num4, num5)
    print(resu)
และแสดงผลลัพธ์ที่เราต้องการ
ผลลัพธ์ที่ได้
Python Knowledge-1.png
Python Knowledge-1.png (6.23 KiB) Viewed 9 times
fullcode
Code: Select all
# -*- coding:utf-8 -*
import psycopg2 as p

con = p.connect(
    host='localhost',
    database='ben01',
    user='postgres',
    password='postgres'
)


def sum_ver():
    cur = con.cursor()
    cur.execute("SELECT latest_version FROM ir_module_module where state = 'installed'")
    total = cur.fetchall()
    num1 = 0
    num2 = 0
    num3 = 0
    num4 = 0
    num5 = 0

    for row in total:
        for i in row:
            sp = i.split('.')
            sp.append('0')
            num1 += int(sp[0])
            num2 += int(sp[1])
            num3 += int(sp[2])
            num4 += int(sp[3])
            num5 += int(sp[4])
    resu = "Summery Version = {}.{}.{}.{}.{}".format(num1, num2, num3, num4, num5)
    print(resu)
    
    if __name__ == '__main__':
    sum_ver()
อ้างอิง
viewtopic.php?f=16&t=64136
https://www.w3schools.com/python/ref_string_split.asp
https://www.pythonforbeginners.com/dictionary/python-split
Read full post »

พื้นที่โฆษณา

Free Hosting

พื้นที่โฆษณา

Free Hosting
 

Copyright © สอนเขียนโปรแกรม html php css Java SQL jQuery XML Ajax Design by ScriptMasterWebDesign | Theme by ScriptMasterWebDesign | Powered by HosTing