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

Cấu hình php.ini trong Windows

Sau khi cài đặt Apache, download PHP (giải nén), tạo file info.php trong APACHE_DIR/htdocs/

<?php
phpinfo();
?>

Để chạy được http://localhost/info.php cần thêm vào APACHE_DIR/conf/httpd.conf hai dòng dạng như  sau(tùy thuộc vào phiên bản sử dụng)

LoadModule php5_module C:/php/php5apache2_2.dll
AddType application/x-httpd-php .php

Restart Apache là ta đã load được trang info.php trên trình duyệt. Để xác định đường dẫn tuyệt đối cho file php.ini mà Apache sẽ load khi chạy PHP, ta phải thêm vào một dòng nữa

PHPIniDir C:/php/

* Để chạy MySQL, phải copy libmysql.dll vào thư mục bin của Apache
* Tham khảo thêm tại http://vn.php.net/install.windows.manual

Using transaction in MySQL / PHP

Why Transactions

Anywhere data integrity is an absolute, transactions will be there. Banks, eCommerce sites, inventory systems, financial systems or any ofther kind of data application that requires data to be stored safely. Transactions are not for everyone or for every situation. Their is a performance hit with transactions. So if you are storing hundreds of thousands of log entries and a few missing ones would not hurt, then transactions are not for you. But if you are building an inventory system that connects accounting and the shipping departments together and any loss of data could mean lost money, well, the answer is clear.

Example 1 Non-Transaction

$userid = 2; $child = $userid * 3;
mysql_query(“delete from account where id=” . $userid)
mysql_query(“update account set ballance=1000 where id=” . $child)

Lets say the above transaction failed or the server shut down just after the delete, this would mean the following update would have never taken place. Depending on your database, synchronization may now be lost.

Example 2 Transaction

mysql_query(“begin”)
mysql_query(“delete from abc where id=2”)
mysql_query(“update abc where id=4”)
if (mysql_error())
mysql_query(“rollback”)
else
mysql_query(“commit”)

In this situation a failure could be captured and any modifications could be safely stored or removed. The beauty of a transaction. That is right, a failure would allow you to remove ALL changes that took place, effectively restoring your database to its previous state.

AUTOINDEX NOTE:
Autoindex or primary auto_increment fields are not rolled back to the previous number. The data is removed from the database, but the autoindex persists. This is for multi-user saftey and redundancy purposes.

Cài đặt để lập trình java

Download JDK từ SUN:
– http://java.sun.com/javase/downloads/index.jsp
Thấy nhiều cái có thể download quá há ^^, biết chọn cái nào giờ? Tìm đến cái chỗ Java SE Development Kit (JDK) ý, đó là cái dân lập trình cần.

Về cơ bản, khi có JDK này rồi thì bạn đã hoàn toàn có thể viết và chạy chương trình bằng Java với một trình soạn thảo bất kì, đơn giản nhất là Notepad

Còn nếu bạn cần IDE để tiện cho việc viết code, phát triển – quản lý project, thì có nhiều để bạn chọn lựa như Eclipse, MyEclipse, NetBean, JCreate Pro…

Muốn viết web với JSP thì cài thêm Apache Tomcat là ổn.
Còn muốn vọc lập trình với thiết bị di động thì tìm cài J2ME thì phải. Chưa xài nên hem rõ nữa :-j

Get Cookie From HttpWebResponse In C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace MyHTTP
{
    class Program
    {
        static void Main(string[] args) {
            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(“http://huypv.net/blog”);
            request.Method = “GET”;
            request.CookieContainer = new CookieContainer();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            foreach (Cookie cook in response.Cookies)
            {
                Console.WriteLine(“Cookie:”);
                Console.WriteLine(“{0} = {1}”, cook.Name, cook.Value);
                Console.WriteLine(“Domain: {0}”, cook.Domain);
                Console.WriteLine(“Path: {0}”, cook.Path);
                Console.WriteLine(“Port: {0}”, cook.Port);
                Console.WriteLine(“Secure: {0}”, cook.Secure);

                Console.WriteLine(“When issued: {0}”, cook.TimeStamp);
                Console.WriteLine(“Expires: {0} (expired? {1})”,
                    cook.Expires, cook.Expired);
                Console.WriteLine(“Don’t save: {0}”, cook.Discard);
                Console.WriteLine(“Comment: {0}”, cook.Comment);
                Console.WriteLine(“Uri for comments: {0}”, cook.CommentUri);
                Console.WriteLine(“Version: RFC {0}”, cook.Version == 1 ? “2109” : “2965”);

                // Show the string representation of the cookie.
                Console.WriteLine(“String: {0}”, cook.ToString());
            }
            Console.ReadKey();
        }
    }
}