March, 2008 Archive
March 14th, 2008 by cpcpyc in เรื่องทั่วไป
»
March 13th, 2008 by +::T@ng::+ in PHP
Discover what you should expect from an integrated development environment (IDE), and compare the cost and benefits of seven popular IDE choices.
Writing an ongoing series of articles on PHP gives you a lot of insight into the world of PHP developers. I’ve talked with many PHP programmers, and one thing that surprises me most is how few use IDEs. Most use text editors, such as Notepad on Microsoft® Windows®, Emacs, or Vim.
The text editors I mentioned (and others I didn’t) are great — I don’t want to start a pointless war over which editor is better. However, no text editor really gives you much insight into your PHP code. In particular, none views a PHP project as more than a directory of files. Let me take you into the world of IDEs, show what you can — or should — expect from them, and provide seven examples from the most popular IDE options.
What is an IDE?
In short, an IDE provides a one-stop shop for your coding work. An IDE contains an editor in which you can edit the code, debug the code, view your code in a browser (often embedded), and check in and out of source code control. To support that functionality, an IDE has a set of features you don’t find in a basic editor, such as Notepad or Vim. Again, you can extend editors to do a lot of these things, but IDEs have all this functionality in one tidy package — typically preconfigured:
- Projects
- A key distinguishing feature of an IDE is that it looks at a PHP application as a project, not just a set of files. That containing concept — the project — maintains extra information, such as the configuration of the source code control, the database settings for debugging purposes, and the location of certain key directories.
- Debugging
- Another handy feature is integrated debugging. With this functionality, you can set breakpoints in the editor at which the PHP interpreter stops during execution of the script. From there, you can inspect the values of local variables to diagnose issues in the code. It’s a healthy alternative to sprinkling
echo
statements through your code to check values or using the error log to get the values of variables.
- Code intelligence
- PHP is a very regular programming language, which means that it follows simple patterns. Not only do these patterns make it easy to write, they make it easy for an IDE to inspect the code in your project. In addition, they help you while writing by displaying the results of their inspection. For example, if you define a class with the name
MyClass
in your project, the IDE then provides a pop-up window that includes MyClass
as an option as soon as you type the keyword new
. As you use the object of that type, the IDE shows its available methods and instance variables. When you start typing a function call, the IDE helps you by displaying the available arguments. Honestly, this is the No. 1 reason you should use an IDE and not a text editor. This type of code intelligence can save you hours of mistyped class names, method names, and wrong arguments.
- Class view
- A side effect of having a code intelligence engine in the IDE is that the IDE can produce a class view of the project. Instead of showing the files, the system can show you the different classes you have defined, regardless of the file they’re in. As you click the classes, your editor is taken to that file and the selection placed on the class, method, or instance variable. It’s a much nicer way of navigating around big projects.
- Support for multiple languages
- Each IDE covered here supports not just PHP but a collection of the related languages: JavaScript, Structured Query Language (SQL), Hypertext Markup Language (HTML), and Cascading Style Sheets (CSS). Support for HTML and CSS are often the best, because it’s simpler. The support for JavaScript often comes down to syntax highlighting, but something is better than nothing.
- Source code control
- All the IDEs evaluated here support some connection to a source code control system, which allows you to maintain versions of the files in your project over time. You can mark particular versions of the files as a release, then revert to them when you want to roll out changes you’ve made. It’s critical in team environments to use a source code control system, but it’s important for individuals to use one, as well. A good source code control system can save you when a disk blows up or when the customer suddenly wants the version before last, rather than what you have today. Most of the IDEs support Concurrent Version System (CVS) and Subversion, which are open source control systems. One IDE supports Perforce, a commercial source code control system.
- FTP/SFTP integration
- Related to source code control is the ability to use FTP for the most recent code to the server. This is a lot easier than using an FTP client or packing up the files yourself, sending them to the server, and unpacking them.
- Database navigation
- A helpful but not essential feature is database navigation. With this feature, you can browse the database your application talks to, find out the table and field names, and run queries. Some systems even automate writing some of the database access code for you.
- Integrated Web browser
- Some of the IDEs support an integrated Web browser that can navigate directly to the page you’re editing with additional arguments you specify, the browser being hosted within the IDE or invoked externally. To be honest, I’m not a huge fan of the integrated browser because I don’t mind switching between editing the code and viewing the result in two separate applications. But I can see the attraction, and it’s not required that you use it.
- Snippets
- The last feature I found in all these IDEs was support for both canned and custom code snippets. Snippets are little fragments of code that perform small tasks, such as running a regular expression on some input, connecting to the database, and querying the database.
That sums up the core features you can expect from a purchased or open source IDE today. From here, we look at some popular IDEs. We’ll show some pictures of what they look like; and explain what they support, and how much they cost, if anything.
Eclipse
Two plug-ins support PHP in the Eclipse development platform. The first, PHP IDE Project, is an Eclipse Foundation project, which means it is released under the Eclipse license and is developed using the Eclipse Foundation’s tools and processes.
The other is PHPEclipse and is developed independently. As with Eclipse, both run on the Big Three operating systems: Windows, Linux®, and Mac OS X. You can download just the plug-ins (if you already use Eclipse), or download a pre-fab version with everything you need.
Both plug-ins support core IDE features you would expect to find. The code intelligence is rock-solid, pops up when you want it, and displays all the information you need for classes, methods, and arguments.
Figure 1 shows PHPEclipse running on Mac OS X. On the left side is the project view with the files in the project. Below that is the class view, which shows any classes I’ve defined. In the center is my code. I can have multiple files open in multiple tabs simultaneously. On the right side are panels for debugging and browsing. This is the stock PHPEclipse user interface.
Figure 1. PHPEclipse on OS X

Figure 2 shows the PHP IDE Project plug-in from the Eclipse Foundation in action.
Figure 2. PHP IDE Project on OS X

If you can’t tell the difference, I don’t blame you. The two look very similar because both rely on the Eclipse platform to present their code browsing and intelligence features. Consistency among Eclipse plug-in GUIs is a good thing.
I did not find that either plug-in locks you into a particular Eclipse project. You can always change one plug-in for another. In my limited testing, I preferred the PHP IDE Project plug-in because it felt better integrated to me, and the performance of the code intelligence features seemed snappier. Try both to see which you prefer.
The downside to both plug-ins is that because Eclipse can be used for almost any programming language, the UI is not tailored to PHP. As a result, Eclipse’s terminology is a bit alien at first. If you’re new to Eclipse, this results in a steeper learning curve for these plug-ins than the other IDEs. On the other hand, if you know Eclipse, you’re ahead of the game using either PHPEclipse or PHP IDE Project.
The big upside to Eclipse and these plug-ins? They are free. As in free. And stable. And reliable. Oh, did I mention they’re free?
Komodo
Next up is ActiveState’s Komodo IDE. This IDE runs on Windows, Mac OS X, and Linux, and it supports the usual open source language suspects — Perl, PHP, and Ruby. The code intelligence engine is solid. It scans all your language installations to find custom extensions, such as PEAR modules. On the project side, it supports integration with CVS, Subversion, and Perforce, as well as allowing for direct FTP transfer of code to the server.
Figure 3 shows Komodo running on Windows. A class view is on the left, and the project view is on the right. Dominating the center is the tabbed code view. To the bottom are the breakpoints for the debugger, the command output, and so on. As with all these systems, you can significantly customize the UI to match your preferences.
Figure 3. Komodo running on Windows

Komodo is a commercial product. At the time of writing, the IDE was available in personal (US$29.95) or professional (US$299.95) versions. One of the unique features of it is its regular expression debugger. That alone is almost worth the price of admission if you’re new to regular expressions or if you use advanced regular expression features.
On the downside, there’s no database integration that I could find, and I encountered some small issues with the code intelligence not always wanting to pop up. Overall, however, Komodo is a robust, feature-rich, and reliable IDE for PHP.
PHP Designer
PHP Designer takes a different tack from the other IDEs. Sure, it supports limited code intelligence. However, its focus is on further enabling the design aspect of the PHP Web application. This is evidenced by its integrated browser being adorned with pixel rulers to help in positioning elements on the page.
Figure 4 shows the coding side of PHP Designer in action.
Figure 4. PHP Designer on Windows

While the PHP code intelligence and debugging features are light in PHP Designer, the HTML, CSS, and JavaScript intelligence is much stronger than the rest of the field. PHP Designer fits in the space between a programmer’s IDE, which concentrates primarily on the code, and Adobe Dreamweaver, which leans heavily toward design. If you’re looking for something in that space, it’s worth looking at PHP Designer, because the IDE is free for personal use and US$55 for the professional edition.
PhpED
NuSphere’s Windows-only PhpED is easily the most feature-laden of all the IDEs presented here. It’s got a great internal debugger and gets extra marks for putting a debugging tool bar into Microsoft Internet Explorer® for easy access to page debugging.
Figure 5 shows PHPEd developing a PHP application in Windows. On the far left is the file view of the project. To the right of that is the class view, and to the right of that is the code view. Below are status read-outs. In case you haven’t noticed yet, all these IDEs follow the same basic design aesthetic.
Figure 5. PhpED on Windows

Standout features of PhpED include a great debugger, excellent database access, good code intelligence features, and integrated PHP help. PhpED prices range from US$119 for the basic version to US$495 for the professional version. A trial version is also available.
PHPEdit
PHPEdit, from WaterProof Software, feels like Microsoft’s msdev environment applied to PHP — and that’s not a bad thing. PHPEdit is a Windows-only IDE, and it’s easy to set up. It even comes with a version of PHP ready to go. It does great on code intelligence for PHP, CSS, and HTML but does very little for JavaScript. Figure 6 shows PHPEdit in action.
Figure 6. PHPEdit on Windows

To help with deployment, PHPEdit connects to CVS and Subversion, as well as FTP and its own proprietary ezDeployment system. To help speed development, in addition to the code intelligence features, the IDE has an excellent canned template library of code samples to which you can add on. The evaluation version of PHPEdit is available at no cost, but to get the real deal, it will cost US$89.
Zend Studio
Finally, we come to Zend Studio, listed last here only because it starts with a Z. It should probably be first on your mind. Why? Because it comes from Zend — the folks behind PHP. Oh, and it’s good. It runs on the Big Three: Windows, Mac OS X, and Linux. And it comes with absolutely everything you need: PHP V4, PHP V5 — the whole deal. Yes, it takes a long time to download, but it’s worth it.
As an IDE, Zend Studio is top-notch. It has all the code intelligence features you could want on both the built-in libraries and on custom code. It also has excellent debugging that’s a snap to set up. To get your code into the repository, Zend Studio connects to both CVS and Subversion. To get your code to the server, there’s integrated FTP. Zend Studio, looking fittingly handsome on the Macintosh, is shown in Figure 7.
Figure 7. Zend Studio on the Mac

As with some of the other IDEs, code snippet support is built in to make cranking out the code easy. The IDE also integrates directly with your database to give you insight into the available tables and fields.
The standard edition of Zend Studio is US$99, and the professional edition is US$299. Some of the features I talked about here are held back from the standard edition. A trial version of Zend Studio is available at no cost.
Conclusion
With so many excellent IDE options out there — some of which are even free — I can’t see any reason not to give one a try, particularly if you’re a professional. You can have either your company or your personal consultancy expense a portion or all the cost of any of the commercial products. When you consider the time wasted just on using echo
statements to debug your code versus using an integrated debugger, the purchase price of this IDEs is a no-brainer.
Resources
Learn
- PHP.net is an excellent resource for PHP developers.
- For a series of developerWorks tutorials on learning to program with PHP, see the “Learning PHP” series.
- Visit IBM developerWorks’ PHP project resources to learn more about PHP.
- Stay current with developerWorks technical events and webcasts.
- Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
- Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM’s products.
- To listen to interesting interviews and discussions for software developers, be sure to check out developerWorks podcasts.
Get products and technologies
Discuss
»
March 11th, 2008 by nual in Oracle, งานพัฒนาและบำรุงรักษาฯ
ตามที่สำนักฯ มีแผนปรับปรุงระบบฐานข้อมูล เพื่อเพิ่มประสิทธิภาพในการให้บริการเซิร์ฟเวอร์ดาต้าเบส มีผลให้ระบบงาน บางระบบ จำเป็นต้องปรับปรุงโปรแกรม และ รายงาน เพื่อให้สามารถใช้งานได้กับระบบฐานข้อมูลใหม่ ดังนี้
ที่
|
ระบบงาน |
ผู้รับผิดชอบ |
ผู้ช่วยปรับปรุงระบบ |
1 |
งานเงินเดือน |
กัลยกร |
- |
2 |
งานงบประมาณ |
สุภิญญา |
ศศิธร |
3 |
งานกองทุนสวัสดิภาพ |
สุภิญญา |
ศศิธร |
4 |
งานกู้เงินเพื่อที่อยู่อาศัย |
สุภิญญา |
ศศิธร |
5 |
งานบุคลากร – การเลื่อนขั้นพนักงาน |
กัลยกร |
มัลลิกา |
6 |
งานทะเบียนนิสิต |
วาสนา, กัลยกร, มนู, ศศิธร |
- |
7 |
งานบุคลากร |
ประสพสุข |
- |
ทั้งนี้ฝ่ายระบบคอมพิวเตอร์และเครือข่าย ได้แจ้งแผนการติดตั้งระบบดาต้าเบส RAC (ดังแนบ) จึงขอให้ผู้รับผิดชอบแต่ละระบบงาน ทราบ และปรับปรุงระบบ ให้เสร็จสมบูรณ์ตามกำหนดการ
เอกสารแนบ
แผนโครงการติดตั้งระบบดาต้าเบส RAC และ ระบบ DR mar04161801.pdf
»
March 10th, 2008 by cpcpyc in เรื่องทั่วไป
ซันได้ออกมาประกาศว่าพวกเขาได้เริ่มพัฒนา Java Virtual Machine ให้กับไอโฟนแล้วด้วย SDK ที่แอปเปิลเพิ่งปล่อยออกมา โดยพวกเขาสัญญาว่าจะทำให้แอพพลิเคชั่นที่พัฒนาด้วย Java สามารถใช้งานได้ในระดับเดียวกันกับ Native Application ของไอโฟนเลยทีเดียวสำหรับเวอร์ชั่นโดยเจาะจงของ Java สำหรับไอโฟนจะเป็น Java Micro Edition (ME) ซึ่งจะสามารถทำให้ไอโฟนสามารถรันแอพพลิเคชั่นที่พัฒนาด้วย Java ที่มีอยู่ก่อนแล้วมากมาย โดยซันเองคาดว่า Java Virtual Machine น่าจะเสร็จสมบูรณ์หลังจากเดือนมิถุนายนนี้
โดยซันได้ยกตัวอย่างแอพพลิเคชั่นที่รันได้ด้วย Java ME มาด้วย เช่น EA Sims Bowling, Scrabble, Harry Potter and the Order of the Phoenix, Libris eBook reader และอื่น ๆ อีกมากมาย
ที่มา - MacRumors
»
March 8th, 2008 by cpcpyc in PHP
เราพบว่า PHP ช่วยในการสร้างเว็บไซต์แบบ dynamic เพราะเป็นภาษาที่มีความยุ่งยากน้อยที่สุด และสนุกที่สุด การสร้างเว็บไซต์เหล่านี้ เราจำเป็นต้องใช้ฐานข้อมูลในการถึงข้อมูลเพื่อการ login, ในการดึงข้อมูลข่าวสารเพื่อแสดงบนเว็บเพจ และในการจัดเก็บข้อมูลที่เรา post ในกระทู้ ดังนั้นเราจึงใช้ MySQL ซึ่งเป็นระบบฐานข้อมูลที่อยู่ในความนิยมสำหรับทำงานเหล่านี้ แต่เมื่อเราพบว่า เว็บไซต์ของเราเป็นที่นิยมมากกว่าที่เราคิดไว้ เราก็จะพบว่า MySQL ไม่สามารถจัดการงานข้อมูลเยอะๆ ของเราได้ มันก็ถึงเวลาสมควรที่จะเปลี่ยนไปใช้ระบบฐานข้อมูลอื่นแล้ว
แต่ PHP ใช้การเข้าถึงระบบฐานข้อมูล ด้วยวิธีที่แตกต่างกัน ถ้าจะเข้าถึง MySQL เราจะใช้ mysql_connect() และเมื่อเราตัดสินใจที่จะ upgrade เป็น Oracle หรือ MS SQL Server เราจะใช้ ocilogon() หรือ mssql_connect() แทน และสิ่งที่เลวร้ายไปกว่านั้นก็คือ parameter ที่เราใช้สำหรับการเข้าถึงนั้นก็แตกต่างกันด้วยเช่นกัน ก็จะเหมือน ระบบฐานข้อมูลหนึ่งพูด po-tato อีกระบบฐานข้อมูลพูด pota-to
Let’s call the whole thing off เลิกการเรียกใช้ทุกอย่าง
เมื่อเป็นเช่นนี้ การใช้ database wrapper library เช่น ADODB จึงเป็นประโยชน์อย่างมาก เมื่อเราต้องการความมั่นใจในการใช้งานแบบ portability ซึ่งการใช้ wrapper library นี้ เราจะมี common API ที่รองรับการติดต่อกับระบบฐานข้อมูลใดๆ ก็ได้ ทำให้เราไม่จำเป็นต้องเปลี่ยนคำสั่งในการติดต่อฐานข้อมูลแต่ละชนิดทุกครั้งที่เราเปลี่ยนระบบฐานข้อมูล
ADODB ย่อมาจาก Active Data Objects DataBase ซึ่งปัจจุบันรองรับการทำงานกับ MySQL, PostgreSQL, Oracle, Interbase, Microsoft SQL Server, Access, FoxPro, Sybase, ODBC และ ADO
ตัวอย่าง MySQL
แน่นอนว่า ระบบฐานข้อมูลที่ใช้กันมากที่สุดกับ PHP คือ MySQL ดังนั้น เราคงคุ้นเคยกับ code ต่อไปนี้ มันจะติดต่อกับ MySQL Server ที่ localhost, ฐานข้อมูล คือ mydb และใช้คำสั่ง SQL select ซึ่งผลลัพธ์จะพิมพ์ออกมาทีละบรรทัด
// ทำการติดต่อไปยังฐานข้อมูล
$db = mysql_connect(”localhost”, “root”, “password”);
mysql_select_db(”mydb”,$db);
// ใช้คำสั่ง SQL
$result = mysql_query(”SELECT * FROM employees”,$db);
if ($result === false) die(”failed”);
// วนลูปแถวข้อมูลที่ได้มา
while ($fields = mysql_fetch_row($result)) {
// วนลูป field ในแถวข้อมูล
for ($i=0, $max=sizeof($fields); $i < $max; $i++) {
print $fields[$i].’ ‘;
}
print ”
n”;
}
ถ้าเราใช้ ADODB เราจะได้ code เป็นดังนี้
include(”adodb.inc.php”);
$db = NewADOConnection(’mysql’);
$db->Connect(”localhost”, “root”, “password”, “mydb”);
$result = $db->Execute(”SELECT * FROM employees”);
if ($result === false) die(”failed”);
while (!$result->EOF) {
for ($i=0, $max=$result->FieldCount(); $i < $max; $i++)
print $result->fields[$i].’ ‘;
$result->MoveNext();
print ”
n”;
}
ดังนั้น ถ้าเราจะเปลี่ยนระบบฐานข้อมูลเป็น Oracle ก็สามารถทำได้ง่าย เพียงแค่เปลี่ยน code ในบรรทัดที่ 2 ให้เป็น
$db = NewADOConnection(’oracle’);
เรามาดูรายละเอียดของ code กัน
การติดต่อกับระบบฐานข้อมูล
include(”adodb.inc.php”);
$db = NewADOConnection(’mysql’);
$db->Connect(”localhost”, “root”, “password”, “mydb”);
การเขียน code เพื่อติดต่อกับระบบฐานข้อมูล มีความยุ่งยากกว่าของ MySQL เพราะความจำเป็นในการติดต่อของเรามันยุ่งยากกว่า ใน ADODB เราใช้วิธี object-oriented ในการจัดการความซับซ้อนของการจัดการระบบฐานข้อมูลหลายๆ ระบบ เรามี class ต่างๆ ที่ใช้ในการจัดการระบบฐานข้อมูลที่แตกต่างกัน แต่ไม่ต้องกังวล ถ้าเราไม่คุ้นเคยกับการเขียน object-oriented ความซับซ้อนต่างๆ ถูกซ่อนไว้ภายใน function NewADOConnection() แล้ว
เพียงแค่จำไว้ว่า เราเพียงแค่ใช้ PHP code ในการระบุระบบฐานข้อมูลที่เราจะติดต่อด้วยเท่านั้น โดยการเรียก NewADOConnection(databasedriver) ซึ่ง database driver ที่ใช้คือ mysql, mssql, oracle, oci8, postgres, sybase, vfp, access, ibase และอื่นๆ อีกมากมาย
หลังจากนั้น ในตัวอย่าง เราจึงสร้าง class สำหรับการติดต่อระบบฐานข้อมูลใหม่ โดยใช้ NewADOConnection() และสุดท้ายทำการติดต่อระบบฐานข้อมูลโดยใช้ $db->Connect()
การใช้คำสั่ง SQL
$result = $db->Execute(”SELECT * FROM employees”);
if ($result === false) die(”failed”);
การส่งคำสั่ง SQL ให้กับ server ทำแบบโดยตรง ซึ่ง method Execute() จะคืนค่า recordset object ที่ได้จากการสั่ง execute สำเร็จกลับมา ซึ่งเราควรตรวจสอบ $result ด้วยว่าสำเร็จ หรือล้มเหลว
ผู้ที่เริ่มต้นใช้งาน อาจจะสับสนว่า มี object 2 ชนิดที่ใช้ใน ADODB นั่นคือ connection object และ recordset object แล้วเราจะใช้ object เหล่านี้เมื่อไร
สำหรับ connection object หรือ $db จะใช้ในการติดต่อกับระบบฐานข้อมูล, จัดรูปแบบคำสั่ง SQL และดึงข้อมูลจากระบบฐานข้อมูล ส่วน recordset object จะใช้ในการดึงผลลัพธ์ และจัดรูปแบบข้อมูลที่ได้เป็น text หรือเป็น array
ADODB ได้มี function มากมายที่ช่วยในการใช้คำสั่ง INSERT และ UPDATE ง่ายขึ้น ซึ่งเราจะอธิบายในส่วนต่อไป
การดึงข้อมูล
while (!$result->EOF) {
for ($i=0, $max=$result->FieldCount(); $i < $max; $i++)
print $result->fields[$i].’ ‘;
$result->MoveNext();
print ”
n”;
}
แบบอย่างของการดึงข้อมูล เหมือนกับการอ่านไฟล์ ในแต่ละบรรทัด เราจะตรวจสอบก่อนว่า เราอ่านมาถึงบรรทัดสุดท้าย (EOF) หรือยัง ถ้ายังไม่ถึงบรรทัดสุดท้าย จะวนลูปไปทีละ field ในแถวข้อมูลนั้น แล้วก็วนไปอ่านบรรทัดต่อไป (MoveNext) และก็ทำซ้ำไปเรื่อยๆ
$result->fields[] เป็น array ที่ถูกสร้างขึ้นโดย PHP database extension ซึ่งบาง database extension ไม่มีการจัดลำดับของ array โดยใช้ชื่อ field ถ้าเราต้องการบังคับให้เรียงลำดับโดยใช้ชื่อ หรือทำ associative array เราจะใช้ตัวแปร global คือ $ADODB_FETCH_MODE
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs1 = $db->Execute(’select * from table’);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs2 = $db->Execute(’select * from table’);
print_r($rs1->fields); // shows array([0]=>’v0′,[1] =>’v1′)
print_r($rs2->fields); // shows array([’col1′]=>’v0′,[’col2′] =>’v1′)
จากตัวอย่างข้างบน recordset ทั้งสองอัน จะจัดเก็บ และใช้ fetch mode ที่ต่างกัน แต่อยู่บนพื้นฐานของการกำหนด $ADODB_FETCH_MODE เมื่อ recordset ถูกสร้างโดยใช้ method Execute()
ADOConnect
เป็น Object ที่ใช้ในการติดต่อฐานข้อมูล, สั่งให้ทำงานตามคำสั่ง SQL และกำหนด utility function สำหรับมาตรฐานในการจัดรูปแบบของคำสั่ง SQL เช่นการนำมารวมกัน หรือจัดรูปแบบวันที่
Function อื่นๆ
$recordset->Move($pos) ใช้ในการวิ่งไปยังแถวข้อมูลที่ระบุ ADODB จะรองรับการวิ่งไปบรรทัดข้างหน้าในทุกระบบฐานข้อมูล บางระบบฐานข้อมูลจะไม่รองรับการวิ่งย้อนกลับไปบรรทัดก่อนหน้า ซึ่งก็ไม่ใช่ปัญหาใหญ่อะไร เพราะเราสามารถเก็บข้อมูลเหล่านี้ไว้ เพื่อการวิ่งย้อนกลับได้อยู่แล้ว
$recordset->RecordCount() จะ return จำนวนแถวข้อมูลที่ได้จากการสั่งคำสั่ง SQL บางระบบฐานข้อมูลที่ไม่รองรับการทำงานนี้ จะส่งค่า -1 กลับมา
$recordset->GetArray() จะ return ผลลัพธ์กลับมาเป็น array
rs2html($recordset) เป็น function ที่สร้างตาราง HTML โดยใช้ข้อมูลจาก $recordset ในการสร้าง ตัวอย่างการใช้งาน แสดงเป็นตัวหนาใน code นี้
include(’adodb.inc.php’);
include(’tohtml.inc.php’); /* includes the rs2html function */
$conn = &ADONewConnection(’mysql’);
$conn->PConnect(’localhost’,'userid’,'password’,'database’);
$rs = $conn->Execute(’select * from table’);
rs2html($rs); /* recordset to html table */
Advanced Material
การใช้ Inserts และ Updates
จากตัวอย่างนี้ เราต้องการเพิ่มข้อมูลต่อไปนี้เข้าไปในระบบฐานข้อมูล
ID = 3
TheDate = mktime(0,0,0,8,31,2001) /* 31st August 2001 */
Note = sugar why don’t we call it off
ถ้าเราย้ายไประบบฐานข้อมูลอื่นๆ เราก็ไม่ต้องแก้ไข code มากนัก
จากตัวอย่างนี้ เราจะพบปัญหาแรกคือ ระบบฐานข้อมูลแต่ละอันใช้รูปแบบวันที่ที่แตกต่างกัน เช่น MySQL จะใช้รูปแบบ YYYY-MM-DD แต่ระบบฐานข้อมูลอื่น จะใช้รูปแบบวันที่อื่น ด้วยเหตุนี้ ADODB จึงมี function ชื่อว่า DBDate() เพื่อแก้ปัญหานี้ โดย function นี้จะแปลงรูปแบบวันที่ให้ถูกต้อง
ปัญหาถัดไป คือ การใช้ ‘ ในคำว่า ” don’t ” ใน MySQL เราสามารถใส่คำว่า ” don’t ” ได้เลย แต่บางระบบฐานข้อมูล เช่น Sybase, Access หรือ MS SQL Server เราต้องใส่คำว่า ” don”t ” แทน ดังนั้น ADODB จึงมี function ชื่อว่า qstr() ให้ใช้ เพื่อแก้ปัญหานี้
เมื่อเป็นเช่นนี้ เราจึงใช้ 2 function นี้ในการนำเข้าข้อมูล
$sql = “INSERT INTO table (id, thedate,note) values (”
. $ID . ‘,’
. $db->DBDate($TheDate) .’,’
. $db->qstr($Note).”)”;
$db->Execute($sql);
นอกจากนี้ ADODB ยังสนับสนุนการคืนจำนวนแถวข้อมูลที่ถูกแก้ไข หรือลบครั้งล่าสุดด้วย โดยใช้ $connection->Affected_Rows() ส่วน $recordset->Insert_ID() จะคืนค่าหมายเลขล่าสุดที่ถูกสร้างขึ้นอัตโนมัติจากการใช้คำสั่ง insert แต่อย่างไรก็ตาม ยังมีบางระบบฐานข้อมูลที่ไม่สนับสนุนการใช้งานของ 2 function นี้
การใช้ MetaTypes
เราสามารถค้นหาข้อมูลเกี่ยวกับ field หรือ column ต่างๆ ได้โดยการใช้ method FetchField($fieldoffset) ซึ่งจะคืนค่า object ที่มี 3 คุณลักษณะ คือ name, type และ max_length
ตัวอย่างเช่น
$recordset = $conn->Execute(”select adate from table”);
$f0 = $recordset->FetchField(0);
ทำให้
$f0->name มีข้อมูลของ ‘adate’
$f0->type ถูกกำหนดให้เป็น ‘date’
และ max_length จะไม่มีค่า ซึ่งถูกกำหนดให้เป็น -1
อีกปัญหาหนึ่งที่พบในการจัดการระบบฐานข้อมูลที่แตกต่างกัน คือ แต่ละระบบฐานข้อมูลมักจะเรียกชนิดข้อมูลแบบเดียวกันด้วยชื่อที่แตกต่างกัน ตัวอย่างเช่น ชนิดข้อมูลแบบ timestamp จะถูกเรียกเป็น datetime ในระบบฐานข้อมูลหนึ่ง และถูกเรียกเป็น time ในอีกระบบฐานข้อมูล ดังนั้น ADODB จึงมี function พิเศษชื่อว่า MetaType($type, $max_length) ซึ่งช่วยในการจัดมาตรฐานการเรียกชื่อชนิดข้อมูลต่างๆ ดังนี้
C: character and varchar types
X: text or long character (eg. more than 255 bytes wide).
B: blob or binary image
D: date
T: timestamp
L: logical (boolean)
I: integer
N: numeric (float, double, money)
ดังนั้น จากตัวอย่างวันที่ข้างบน เราจะได้ code ดังนี้
$recordset = $conn->Execute(”select adate from table”);
$f0 = $recordset->FetchField(0);
$type = $recordset->MetaType($f0->type, $f0->max_length);
print $type; /* should print ‘D’ */
สนับสนุนการใช้ Select Limit และ Top
ADODB มี function ที่เรียกว่า $connection->SelectLimit($sql, $nrows, $offset) ที่อนุญาตให้เราดึง subset ของ recordset มาใช้งานได้ ซึ่งจะเป็นประโยชน์ต่อการใช้ SELECT TOP ของผลิตภัณฑ์ Microsoft และ SELECT…LIMIT ใน PostgreSQL และ MySQL ซึ่งสามารถนำมาใช้ได้ ถ้าระบบฐานข้อมูลอื่นไม่สนับสนุนการใช้งานนี้
สนับสนุนการทำ Caching
ADODB อนุญาตให้เรา cache ตัว recordset ไว้ใน file system ของเราได้ และจะทำการ requery จากฐานข้อมูลเมื่อถึงเวลาที่กำหนดไว้เท่านั้น โดยใช้คำสั่ง $connection->CacheExecute($secs2cache, $sql) และ $connection->CacheSelectLimit($secs2cache, $sql, $nrows, $offset)
สนับสนุนการจัดการ session ของ PHP4
ADODB ได้สนับสนุนการจัดการ session ของ PHP4 ด้วย ซึ่งเราสามารถจัดเก็บตัวแปร session ในฐานข้อมูล เพื่อการใช้ ADODB ที่มีประสิทธิภาพ
การใช้งานแบบเชิงพาณิชย์
ถ้าเราวางแผนที่จะพัฒนาโปรแกรม PHP ในเชิงพาณิชย์ ที่ต้องการขายได้อีกเรื่อยๆ เราควรจะพิจารณาการใช้ ADODB ซึ่งได้ถูก release โดยใช้ GPL ที่น้อยกว่า ซึ่งหมายความว่า เราสามารถรวมเข้ากับโปรแกรมเชิงพาณิชย์ได้อย่างถูกต้องตามกฏหมาย ในขณะที่เราสามารถเก็บเป็น code ของเราเอง เราจึงแนะนำและสนับสนุนให้ใช้ ADODB ในเชิงพาณิชย์ และเราก็กำลังใช้มันด้วยเช่นกัน
เปรียบเทียบ PHP function ของ Mysql กับ ADOdb
Function
|
Mysql_xxx
|
ADOdb
|
การ connect |
mysql_connect(”localhost”, “root”, “password”); |
include(”adodb.inc.php”); $db = NewADOConnection(’mysql’); $db->Connect(”localhost”, “root”, “password”, “mydb”); |
การ รันคำสั่ง SQL |
mysql_query($sql) |
$db->Execute($sql) |
การวน loop เพื่อแสดงผลข้อมูลทั้งหมด |
while ($fields = mysql_fetch_row($result)) { // วนลูป field ในแถวข้อมูล for ($i=0, $max=sizeof($fields); $i < $max; $i++) {
print $fields[$i].’ ‘;
}
print ”
n”;
} |
while (!$result->EOF) { for ($i=0, $max=$result->FieldCount(); $i < $max; $i++) print $result->fields[$i].’ ‘;
$result->MoveNext();
print ”
n”;
} |
การตรวจจับ error ของคำสั่ง sql |
$result = mysql_query($sql); if ($result === false) die(”failed”); |
$result = $db->Execute($sql); if ($result === false) die(”failed”); |
การยัดค่าใส่ตัวแปล array |
while ( $rs = mysql_fetch_row($result) ) { # process $arr } |
$rs = $db->Execute($sql); if ($rs) while ($arr = $rs->FetchRow()) {
# process $arr
} |
การรับค่าทั้งหมด ของ ผลการ รัน คำสั่ง sql ใส่ตัวแปล |
- |
$db->GetArray(), $db->GetRow($sql) $db->GetAll($sql) |
สร้าง list manu จะผลของ การรันคำสั่ง sql |
- |
$rs = $conn->Execute($sql); print $rs->GetMenu(‘ชื่อlistmanu’,‘ค่าที่ถูกselect’,true); data ต้อง เป็น ( name,id ) |
การแสดงผล ข้อมูล ที่ละหน้า |
ต้องเขียน โค้ดแบ่งหน้า เอง |
include_once(’adodb.inc.php’); include_once(’adodb-pager.inc.php’); session_start();
$db = NewADOConnection(’mysql’);
$db->Connect(’localhost’,'root’,”,’xphplens’);
$sql = “select * from adoxyz “;
$pager = new ADODB_Pager($db,$sql);
$pager->Render($rows_per_page=5); |
นับจำนวน recode ทั้งหมด |
mysql_num_rows($result) |
$db->RecordCount($result) |
แสดงผล error ด้วย pear |
ต้องเขียน ดึง pear มาให้เอง |
include(‘adodb-errorpear.inc.php’); if error แสดง ค่าด้านล้างๆด้เลย $e = ADODB_Pear_Error();
echo ‘
‘,$e->message,‘
‘; |
การ รัน sql เพื่อ จำกัด ประริมาณข้อมูล |
ต้องเขียนที่ คำสั่ง sql |
$db->SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false) |
»
March 7th, 2008 by cpcpyc in เรื่องทั่วไป
ไมโครซอฟท์ออก Internet Explorer 8 Beta 1 ให้ดาวน์โหลดแล้ว โดยบอกว่ารุ่นนี้มีเป้าหมายคือนักพัฒนาและเว็บมาสเตอร์ ที่จะทดสอบเว็บของตนว่าใช้งานกับ IE8 ได้การเปลี่ยนแปลงที่สำคัญของ IE8 คือสนับสนุนมาตรฐานเว็บอย่างจริงจัง (ข่าวเก่า) ส่วนฟีเจอร์อื่นๆ มีดังนี้
- Activities - ปุ่มที่เพิ่มเข้ามาเพื่ออำนวยความสะดวกให้เรานำเนื้อหาไปใช้กับบริการออนไลน์อื่นๆ เช่น ไฮไลท์ข้อความที่เป็นที่อยู่แล้วสั่งค้นหาแผนที่ได้ทันที หรือส่งข้อความไปใน Facebook เป็นต้น สนใจดูวิดีโอ (wmv) ประกอบได้ บริการที่มีในปัจจุบันมีพอสมควร เช่น Facebook, StumbleUpon, eBay, Yahoo! Local และบริการอื่นๆ ในตระกูล Live (รายชื่อทั้งหมด)
- Webslices - คล้ายๆ กับ Webclip ของ Safari คือเราสามารถตัดบางส่วนของเว็บ ส่วนที่อัพเดตบ่อยๆ เช่น ราคาหุ้นหรือสภาพอากาศ แล้วเก็บไว้ดูเฉพาะส่วนนั้นได้ จุดที่ต่างออกไปคือไม่ได้เก็บไว้บน Dashboard แต่ทำเป็นปุ่มไว้ใน Toolbar แทน อยากรู้ข้อมูลก็กดปุ่ม แล้ว IE8 จะแสดงเว็บส่วนนั้นขึ้นมาให้ดูใน popup menu
- Developer Toolbar สำหรับการดีบั๊กเว็บเพจ
- รายการฟีเจอร์ทั้งหมด
ทั้ง Activities และ Webslices ไมโครซอฟท์ยังเปิดให้นักพัฒนาภายนอกเพิ่มเติมเข้าไปจากที่ไมโครซอฟท์มีมาให้ และนำขึ้นเว็บไซต์ให้คนทั่วไปดาวน์โหลดได้เหมือน Adds-on ของ Firefoxดาวน์โหลดได้แล้ววันนี้ มีเวอร์ชันสำหรับ XP, Vista, 2003, 2008 ทั้งเวอร์ชัน 32 และ 64 บิต สำหรับนักพัฒนาเว็บเพจ ไมโครซอฟท์ยังมี Internet Explorer 8 Beta 1 Whitepapers ให้อ่านเพิ่มเติม
ที่มา - Internet Explorer 8
»
March 6th, 2008 by cpcpyc in PHP
เป็นการเช็ค date format ว่าใส่เข้ามาถูกต้องมั้ย ด้วย regura expression
<?php // Date format (yyyy-mm-dd) checking
$myDate = “2008-01-01″;
if( preg_match(”/(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])/”,
$myDate) )
{
echo “Good date :)”;
}
else
{
echo “Bad date :(”;
}
?>
»
March 5th, 2008 by pichaya in กิจกรรมฝ่าย
เรียน เจ้าหน้าที่ฝ่ายสารสนเทศทุกท่าน
ตามมติที่ประชุมคณะกรรมการบริหารสำนักบริการคอมพิวเตอร์ ครั้งที่ 5/2551 วันที่ 5 มีนานาคม 2551 มีเรื่องที่เกี่ยวข้องกับฝ่าย ที่ขอแจ้งให้เจ้าหน้าที่ทราบและพิจารณาโดยด่วน ดังนี้ (รายละเอียดของสรุปมติที่ประชุม และรายงานการประชุม งานบุคคลและประชุม จะจัดทำแจ้งภายหลัง ตามปกติ)
วาระที่ 3 เรื่องสืบเนื่อง
3.1 การจัดทำแผนกิจกรรมประจำปีสำนักบริการคอมพิวเตอร์
มอบหมายฝ่าย จัดทำปฏิทินกิจกรรมประจำปี (ส่ง ผช.ผอ. คุณเจน)
- ปฏิทินกิจกรรมของฝ่าย แสดงกิจกรรมซึ่งสะท้อนภารกิจหลักของฝ่าย ใช้ประโยชน์ในงานบริหารงานของฝ่าย
- ปฏิทินกิจกรรมในภาพรวมของสำนักฯ ใช้ประโยชน์สำหรับ ปชส. ทั้งภานใน และภายนอก
ฝ่ายสารสนเทศ ดำเนินการ (ขอด่วน ภายใน 17 มีนาคม 2551)
- มอบหมายรองหัวหน้า หัวหน้างาน และเจ้าหน้าที่ฝ่ายทุกคน เสนอรายชื่อกิจกรรมของฝ่าย ทั้งส่วนที่เป็นเรื่องภายในของฝ่าย และภาพรวมของสำนักฯ โดยกิจกรรมของฝ่าย ตัวอย่าง เช่น กำหนดการใช้งานเว็บบริการใหม่………. กำหนดการใช้งานเว็บบริการระบบเดิม……………เวอร์ชันใหม่….. กำหนดการทดสอบระบบ…………. เป็นต้น
3.2 แผนพัฒนาบุคลากร
มอบหมายฝ่าย จัดทำแผนพัฒนาบุคลากร ดังนี้
- เพื่อรายงานในเอกสาร SSR ฝ่าย
- เพื่อเป็นแผนพัฒนาบุคลากร ใช้งานจริงต่อไป
ฝ่ายสารสนเทศ ดำเนินการ (ขอด่วน ภายใน 17 มีนาคม 2551)
- มอบหมายรองหัวหน้า หัวหน้างาน และเจ้าหน้าที่ฝ่ายทุกคน เสนอแผนพัฒนาบุคลากรของฝ่าย
- เสนอรายชื่อหลักสูตรเพิ่มเติมความสามารถ (ไม่ใช่เป็นหลักสูตรพื้นฐาน) ของแต่ละตำแหน่ง แต่ละคน
- เสนอรายการสอบ Certificate ในหลักสูตรที่สนใจและเกี่ยวข้องกับสานงาน และผู้ที่ประสงค์จะสอบ Certificate
3.3 การเหลื่อมเวลา (ดังเอกสารแนบ)
- ใช้งานจริง 1 เมษายน 2551
- มอบหมายฝ่ายสารสนเทศ ปรับปรุงโปรแกรมให้รองรับการปฏิบัติงานเหลื่อมเวลา
วาระที่ 5 เรื่องเสนอเพื่อทราบ
5.2 การประเมินคุณภาพภายในระดับฝ่ายและระดับมหาวิทยาลัยประจำปี 2551
- สำนักบริการคอมพิวเตอร์ รับการประเมินคุณภาพระดับมหาวิทยาลัยฯ ในวันที่ 29-30 ก.ค.2551 โดยจะต้องจัดส่ง SAR ให้สำนักประกันคุณภาพ ภายในวันที่ 2 ก.ค. 2551
- การประเมินในปี 2551 จะประเมินเป็นรายหน่วยงาน แล้วจึงสรุปรวมเป็นกลุ่มหน่วยงาน โดยได้มีการเปลี่ยนแปลงโครงสร้างของคณะกรรมการตรวจสอบระดับฝ่าย และคณะกรรมการประเมินฯ ระดับสำนัก ใหม่ตามรายละเอียดที่แนบมาด้วย
- การตรวจสอบระดับฝ่าย คาดว่าจะตรวจสอบให้เสร็จสิ้นภายใน 30 เม.ย. 2551 โดยจะขึ้นอยู่กับประธาน ซึ่งเป็นบุคลภายนอกสำนัก โดยฝ่ายเก่า จัดทำ SSR ส่งสำนักฯ ภายใน 14 มี.ค. 2551 และฝ่ายใหม่จัดทำ SSR ส่งภายใน 30 มี.ค. 2551
- สำนักฯ ได้เตรียมบุคลากรสำหรับรองรับการตรวจสอบคุณภาพภายในระดับฝ่าย ประจำปี 2551 โดยจัดส่งบุคลากรไปรับการอบรมหลักสูตรของ สกอ. ซึ่งรุ่นสุดท้ายที่บุคลากร สบค.รับการอบรมประมาณวันที่ 23 เม.ย. 2551 ทำให้สบค. มีบุคลากรที่สามารถตรวจสอบระดับฝ่ายได้ 4 คน คือ อ.ประดนเดช ชิดชนก เบ็ญจวรณ และสุภาพร
5.3 การพัฒนาระบบจดหมายอิเล็กทรอนิกส์กลางเพื่อการสื่อสารในภาครัฐ
- เฟสแรก ภายใน 3 เดือน ข้าราชการ ตั้งแต่ระดับ 8 ขึ้นไป ห้ามใช้ free e-mail
- เฟสต่อไป ภายใน 1 ปี ข้าราชการ พนักงาน ทั้งหมด ห้ามใช้ free e-mail
- การห้ามใช้ free e-mail รวมถึงการรับ-ส่งไฟล์ผ่าน Instant Messenging ต่างๆ เช่น MSN เป็นต้น
- การห้ามใช้ free e-mail หมายถึง ไม่ให้ใช้ติดต่อสื่อสารในงานราชการ รวมทั้งการเผยแพร่ e-mail บนนามบัตรด้วย ห้ามใช้ชื่อ free e-mail
- กรณีใช้งานส่วนตัว (จริงๆ) ไม่ได้เกี่ยวข้องกับข้อมูลหรือเรื่องของราชการ สามารถใช้งานได้ (เป็นสิทธิส่วนตัวของแต่ละบุคคล ไม่ได้ห้ามใช้)
5.4 แผนการติดตั้งระบบ DR และดาต้าเบส RAC
- ดังเอกสารแนบ
ฝ่ายสารสนเทศ ดำเนินการ
- ขอให้เจ้าหน้าที่ทุกคน และที่เกี่ยวข้องโดยตรง ร่วมกันเร่งปรับปรุงระบบงานที่มีอยู่ให้รองรับการใช้งาน Oracle RAC ตามกำหนด
เอกสารแนบ
1. เงื่อนไขการลงเวลาปฏิบัติงาน mar04114223.pdf
2. แผนโครงการติดตั้งระบบดาต้าเบส RAC และ ระบบ DR mar04161801.pdf
»
March 5th, 2008 by cpcpyc in เรื่องทั่วไป
ไมโครซอฟท์ประกาศว่า IE8 จะใช้โหมดเรนเดอร์ HTML ตามมาตรฐานของ W3C เป็นค่า default
โดยปกติแล้ว การแสดงผล HTML ในเว็บเบราว์เซอร์จะมีสองโหมดหลักๆ คือ Quirk (สำหรับเว็บเพจที่เขียนไม่ตรงตามมาตรฐาน) และ Standard (อันนี้ตามชื่อ) แต่ปัญหาที่เกิดขึ้นกับ IE7 นั้นคือ Standard mode ของ IE7 มันไม่ตรงตามมาตรฐานเว็บจริง เนื่องจากทีมพัฒนา IE ต้องการรักษาความเข้ากันได้กับ IE6 เอาไว้
พอมาถึงคิวของ IE8 ในตอนแรกไมโครซอฟท์ได้เสนอแนวคิดว่าจะเพิ่มโหมดที่ 3 คือโหมด (true) standard โดยผู้เขียนเว็บต้องระบุใน header ของเพจเอาเอง ซึ่งก็โดนโจมตีอย่างหนัก แต่ล่าสุดบริษัทได้กลับลำบอกว่าจะปรับให้ IE8 ใช้โหมด Standard (อันที่ 2 แต่ตรงตามมาตรฐานจริง) และถึงกับให้เป็น default เลยทีเดียว ไมโครซอฟท์ให้เหตุผลว่าเป็นการทำตามแผน Microsoft Interoperability
1.สร้างการเชื่อมต่อแบบเปิด (open connection)
2.สนับสนุน data portablility (สามารถย้ายข้อมูลข้ามโปรแกรมได้ง่าย)
3.สนับสนุนมาตรฐานอุตสาหกรรม
4.มีส่วนร่วมกับผู้ใช้และชุมชนมากขึ้น รวมถึงชุมชนโอเพนซอร์สด้วย
สรุปว่านี่เป็นเรื่องน่าดีใจของคนทำเว็บว่าสุดท้ายแล้วไมโครซอฟท์ก็ยอมทำตามมาตรฐาน แต่แน่นอนว่ายังมีเว็บอีกจำนวนมากที่เขียนไว้เพื่อรองรับ IE6 อยู่ดีลิงก์อ่านประกอบ
ที่มา - IEBlog, Ars Technica
»
March 4th, 2008 by cpcpyc in งานเขียนคู่มือและทดสอบ, ระบบบัญชีสามมิติ
»