Web KhowLedge

WordPress

  • Tue, 29 Mar 2011 03:04:40 +0000: By: Larry Battle - Comments on: 13 Excellent Plugins To Enhance The Power Of WordPress Admin Section
    "Hellos Bar" is a great addition to my toolkit. Thanks for the article. Check it out on my site. http://bateru.com/news
  • Sun, 27 Mar 2011 02:25:45 +0000: By: Manpreet Singh Rehsi - Comments on: 13 Excellent Plugins To Enhance The Power Of WordPress Admin Section
    I really like faster image insert and hellos bar. Thanks, I am going to use both of the plugin in my blog.
  • Thu, 24 Mar 2011 09:29:09 +0000: By: Alex Kappel - Comments on: 13 Excellent Plugins To Enhance The Power Of WordPress Admin Section
    WPMU Prefill Post is exactly what I need, my problem (Wordpress 3.1) is that I cannot make a template with tables, when I press insert it doesn't look pretty. Anyone who has a similar plugin?
  • Tue, 22 Mar 2011 17:03:09 +0000: By: CPT Code Lookup - Comments on: 13 Excellent Plugins To Enhance The Power Of WordPress Admin Section
    Hello admin, thanks for posting and link back to my site.
  • Mon, 21 Mar 2011 10:25:26 +0000: By: Impression affiches - Comments on: 13 Excellent Plugins To Enhance The Power Of WordPress Admin Section
    Thank you, great selection. These apps are really helpful. I think that hotlink protection is the best.

PHP ภาษาไทย


  • Sat, 19 Nov 2011 01:57:48 +0000: ฝึกตนด้วยการตอบปัญหา - select2web.com » PHP
    ในวันคืนที่เหงาหงอยและอ้างว้าง ว่างงานจากการตาจ้องหน้าจอมือจิ้มคีย์บอร์ดเพื่อเขียนโปรแกรม ผมมักจะไปเยี่ยมเยือนตามเว็บบอร์ด PHP เพื่อไปดูคำถามที่น่าสนใจแล้วก็ตอบ เป็นงานอดิเรก
  • Sat, 24 Sep 2011 13:13:07 +0000: เพิ่มรายการเข้าไปในลิสต์บ้อกด้วย AJAX - select2web.com » PHP
    โจทย์ก็คือ มีฟอร์ม 1 ฟอร์ม ในฟอร์มมีลิสต์บ้อก 1 ตัวและอื่นๆ ลิสต์บ้อกตัวนี้ ถ้าหากไม่มีค่าที่ต้องการ ให้สามารถกดปุ่มเพิ่มค่าเข้าไปในลิสต์บ้อกโดยใช้ AJAX และค่าที่เพิ่มเข้าไปนั้น ต้องเอาไปเก็บในฐานข้อมูลด้วย
  • Wed, 24 Aug 2011 16:39:24 +0000: วิธีสร้าง Virtual host - select2web.com » PHP
    การสร้าง Virtual Host มีประโยชน์ต่อการเขียนโปรแกรมอย่างไร ทำอย่างไร
  • Thu, 18 Aug 2011 17:48:53 +0000: เออเร่อ Fatal error: Allowed memory size of 25165824 bytes exhausted - select2web.com » PHP
    เออเร่อตัวนี้ผมว่า ผู้ฝึกเขียน PHP แทบทุกคนจะต้องเจอ ในเออเร่อแจ้งว่า เราอนุญาติให้ใช้หน่วยความจำแค่นี้นะ แต่รู้สึกว่าจะมีการใช้หน่วยความจำเกินที่กำหนดไว้
  • Wed, 08 Jun 2011 15:06:48 +0000: PHP ว่าด้วยเรื่อง Array() - select2web.com » PHP
    Array หรือ อะเรย์ ในภาษาไทยเป็นตัวแปรประเภทหนึ่ง ที่สามารถเก็บค่าหลายๆค่าไว้ในตัวแปรชื่อเดียวกัน โดยอาศัยการเข้าถึงค่าแต่ละตัวด้วย เลขดัชนีหรือชื่อย่อยประจำตัวภายใน Array

Web Developer ภาษาไทย

  • Tue, 14 Feb 2012 07:48:03 +0000: PHP Script หาผลรวมของค่าใน Array จาก Key เดียวกัน - Web Development and Programming Help.
    พอดีต้องใช้งานลักษณะนี้ เลยไปได้ source จาก stackoverflow.com มาทดลองรันดูได้ผลเป็นที่หน้าพอใจ ดูตัวอย่าง code ด้านล่างครับ อธิบายด้วยตัวมันเองอยู่แล้ว ตัวอย่าง Array PHP Array ( [0] => Array ( [gozhi] => 2 [uzorong] => 1 [ngangla] => 4 [langthel] => 5 ) [1] => Array ( [gozhi] => 5 [uzorong] => 0 [ngangla] => 3 [langthel] => 2 ) [2] => Array ( [gozhi] => 3 [uzorong] => 0 [ngangla] => 1 [langthel] => 3 ) ) ตัวอย่างผลลัพท์ Array ( [gozhi] => 10 [uzorong] => 1 [ngangla] => 8 [langthel] => 10 ) PHP Code ที่ใช้ $newarr=array(); foreach($arrs as $value){ [...]
  • Wed, 01 Feb 2012 08:44:04 +0000: Javascript ดึงชื่อไฟล์และนามสกุลจาก URL - Web Development and Programming Help.
    ขอยกตัวอย่างนะครับเช่น http://www.memo8.com/toolkits/home.html ก็จะได้ filename1 = ‘home.html’ (ชื่อไฟล์+นามสกุล) filename2 = ‘home’ (เฉพาะชื่อไฟล์ไม่มีนามสกุล) file_extension =’html’ (เฉพาะนามสกุล) url = window.location.pathname; filename1 = url.match(/.*\/(.*)$/)[1];// ชื่อไฟล์+นามสกุล home.html filename2 = filename.split(/\./)[0]; // ชื่อไฟล์ไม่มีนามสกุล home file_extension = filename.split(/\./)[1]; // นามสกุลไฟล์ html
  • Tue, 17 Jan 2012 09:25:27 +0000: รูปแบบ Cursor Styles ใน CSS2 และ CSS3 - Web Development and Programming Help.
    ใช้ css มาก็บ่อย บางทีใช้ Cursor Styles ก็ไปค้นในเน็ตเริ่มเสียเวลาเอามาไว้ในเว็บนี้เลยแล้วกัน และด้านล่างนี้เป็นรูปแบบ CSS Cursor แบบต่างๆตั้งแต่ CSS2-CSS3 ลองเอาไปปรับใช้ให้เหมาะกับอินเตอร์เฟสในหน้าเว็บครับ CSS2 Cursor Styles cursor: auto cursor: inherit cursor: crosshair cursor: default cursor: help cursor: move cursor: pointer cursor: progress cursor: text cursor: wait cursor: e-resize cursor: ne-resize cursor: nw-resize cursor: n-resize cursor: se-resize cursor: sw-resize cursor: s-resize cursor: w-resize CSS3 Cursor Styles cursor: none (not IE, Safari, Opera) cursor: context-menu (not Firefox, Chrome) cursor: cell (not Safari) cursor: vertical-text cursor: alias (not Safari) cursor: copy (not Safari) cursor: no-drop cursor: [...]
  • Tue, 17 Jan 2012 07:12:44 +0000: เพิ่ม IGNORE หลังคำสั่ง INSERT เมื่อต้องการละเว้นการ Duplicate entry - Web Development and Programming Help.
    บางครั้งมีการ insert โดย database มีการ set unique key values เพื่อไม่ให้ข้อมูลซ้ำกัน หลายครั้งพอเริ่มคำสั่ง sql เมื่อเจอรายการที่ซ้ำ (Duplicate entry) คำสั่งก็จะหยุดทำงาน อาจจะไม่เหมาะสม ในกรณีข้อมูลเยอะแล้วต้องมาไล่ดูว่ารายการไหนซ้ำ งั้นลองเพิ่ม IGNORE หลังคำสั่ง INSERT เพื่อละเว้นการหยุดการทำงานในกรณี Duplicate entry ตัวอย่างตามด้านล่างครับ INSERT IGNORE INTO TB_NAME (COLUMN) VALUES (DATA);
  • Thu, 22 Dec 2011 09:44:07 +0000: Code PHP สำหรับค้นหาวันที่สุดท้ายของเดือน - Web Development and Programming Help.
    โค้ดตามด้านล่างครับ $LastDate = date(’Y-m-d’,strtotime(’-1 second’,strtotime(’+1 month’,strtotime(date(’m').’/01/’.date(’Y').’ 00:00:00′)))); ที่มา http://ullu.wordpress.com/2007/02/28/find-last-day-of-the-month-in-php/

Tutorials
  • Sun, 04 Oct 2009 05:06:54 +0000: jQuery Tutorial – Create Edit in Place with Ajax - jQuery Wisdom » Tutorials
    Building an edit-in-place solution that saves all data in the background, using Ajax. I’m going to show you two ways that you could use jQuery to accomplish the same effect, or better. An AJAX (or AHAH) proof-of-concept page that allows the visitor to edit the very (x)HTML page they are viewing, without leaving the page. [...]
  • Sat, 03 Oct 2009 14:09:57 +0000: 25 Best Collection of jQuery Menu Design Tutorials - jQuery Wisdom » Tutorials
    Menu is the heart of the navigation for any website. jQuery lets you create attractive and intuitive animated menus. This collection of jQuery menu design tutorials collection lets you create beautiful and animated menus in jQuery with ease. 1. jQuery Tutorial – Create a Sliding Menu Using jQuery This time we’ll be building a sleek [...]
  • Fri, 02 Oct 2009 12:11:46 +0000: jQuery Tutorial – Sleek Drop Down Menu with jQuery & CSS - jQuery Wisdom » Tutorials
    In this tutorial I would like to go over how to create a sleek drop down menu that can also degrade gracefully. Studies show that top navigations tend to get the most visual attention when a user first visits a site. Having organized and intuitive navigation is key — and while most drop down menus [...]
  • Fri, 02 Oct 2009 11:57:49 +0000: jQuery Tutorial – Create A Dropdown Menu using jQuery - jQuery Wisdom » Tutorials
    This article is intended to describe an extremely basic, yet extremely powerful, technique for adding dropdown menus in your application user interface or website design. Dropdown menus and menu bars have been heavily used since the early days of graphical user interfaces. Their use has become ubiquitous, and even expected, in desktop applications, and the [...]
  • Fri, 02 Oct 2009 11:45:27 +0000: jQuery Tutorial – Create iPod-style Drilldown and Flyout Menu - jQuery Wisdom » Tutorials
    The iPod-style menu provides easy navigation of complex nested structures with any number of levels. The entire menu sits within a fixed-size area, and when a node is selected, by default a “Back” link appears below the menu to allow navigation to previous (parent) menus, or set options to show breadcrumb links above the menu [...]

Ajax
  • Tue, 20 Jul 2010 12:19:42 +0000: 50 Useful JavaScript and jQuery Techniques and Plugins - Noupe » AJAX

      

    We are regularly collecting useful JavaScript and jQuery snippets, libraries, articles, tools and resources and present them in compact round-ups here, on Noupe. This time we are again covering some useful JavaScript and jQuery techniques, plugins and tools that may help you improve the user experience for your site.

  • Mon, 04 Jan 2010 13:33:52 +0000: 30 Fresh AJAX Tutorials And Techniques - Noupe » AJAX

      

    Using AJAX on websites and applications is pretty much taken for granted nowadays. Users expect it. They want to be able to edit a page in-place, they want search queries to be auto-suggested, and they want to be able to submit a form without refreshing the page. Why? Because those things make browsing quicker, easier and, more importantly, enjoyable.

  • Wed, 14 Oct 2009 10:26:08 +0000: Free Slideshow, Gallery And Lightboxes Scripts - Noupe » AJAX

      

    For Web design projects, you may find yourself sometimes scrounging around for a simple yet useful image gallery and slideshow. But imagine having a huge collection of AJAX, JavaScript, Lightbox, CSS and Flash-based image galleries at your fingertips. Hopefully, this post will do the trick and provide all the resources you might need.

  • Thu, 13 Aug 2009 01:41:05 +0000: A Simple Twitter App with Ruby on Rails – Building Friendships - Noupe » AJAX

      

    This is the third and final part of series on how to create a twitter style web application with Ruby on Rails. This part will cover how to add friendships between users.

  • Thu, 16 Jul 2009 02:58:35 +0000: A Simple Twitter App with Ruby on Rails – User Authentication - Noupe » AJAX

      

    This article is the second part in a three part series. In the first part we created some basic functionality to allow the user to post messages in a similar way to Twitter. If you have not completed the first part of this tutorial, please do so now.


Html-Css-Techniques
  • Tue, 21 Feb 2012 09:00:04 +0000: Colors of Spring: Color Palettes from Spring Flowers and Foliage - Noupe

      
    As the icy grip of winter closes in tighter many begin to dream of spring. That time of renewed growth and warmer days that tends to draw us back outside and into nature's waiting open arms. With the seeming promise from the old groundhog that we will more than likely be seeing a few more weeks of winter, we thought our readers could use a little piece of spring a bit early.
  • Mon, 20 Feb 2012 08:59:52 +0000: Free Photoshop Alternatives For Editing Photos - Noupe

      
    Photoshop has been the darling of the design industry for decades. It's a fantastic program that has led the way since the release of Photoshop 1 on the Mac way back in 1990.
  • Fri, 17 Feb 2012 08:59:57 +0000: Designing the Web: Photoshop Tutorials for Designing a Website - Noupe

      
    For those of us in the business of designing the web, one area of resources that always prove invaluable to have in our design arsenals is tutorials. Learning how other web designers have crafted their designs, and which tools they always rely on can always help to guide us as we are either developing or honing our own skills. So we search the web for useful tutorials. Well today we have done the searching for you.
  • Thu, 16 Feb 2012 09:00:09 +0000: Hitting the Mark: A Collection of Creative Advertisements - Noupe

      
    Over the last 100 years or so advertising has been integrated into every walk of life. Whether you are working on the internet, relaxing at home watching TV or getting the bus or train to the cinema; you cannot avoid being bombarded with advertisements from all angles.
  • Wed, 15 Feb 2012 09:00:19 +0000: Free Fonts to Make a Great First Impression - Noupe

      
    When you're designing a website, one of the pillars of great design is typography. Typography is an essential part of good web design, yet it's amazing how many designers consistently don't have the proper tools to work with! Talking of course about a quality font library. Even the best designer will struggle to come up with a professional outcome if their font library is lacking in quality.

PHP
  • Wed, 22 Feb 2012 21:05:09 +0000: Wrangle Async Tasks with jQuery Promises - Nettuts+

    Promises are an exciting jQuery feature that make it a breeze to manage async events. They allow you to write clearer, shorter callbacks and keep high-level application logic separate from low-level behaviors.

    Once you understand Promises, you’ll want to use them for everything from AJAX calls to UI flow. That’s a promise!


    Understanding Promises

    Once a Promise is resolved or rejected, it’ll remain in that state forever.

    A Promise is an object that represents a one-time event, typically the outcome of an async task like an AJAX call. At first, a Promise is in a pending state. Eventually, it’s either resolved (meaning the task is done) or rejected (if the task failed). Once a Promise is resolved or rejected, it’ll remain in that state forever, and its callbacks will never fire again.

    You can attach callbacks to the Promise, which will fire when the Promise is resolved or rejected. And you can add more callbacks whenever you want – even after the Promise has been resolved/rejected! (In that case, they’ll fire immediately.)

    Plus, you can combine Promises logically into new Promises. That makes it trivially easy to write code that says, “When all of these things have happened, do this other thing.”

    And that’s all you need to know about Promises in the abstract. There are several JavaScript implementations to choose from. The two most notable are Kris Kowal’s q, based on the CommonJS Promises/A spec, and jQuery Promises (added in jQuery 1.5). Because of jQuery’s ubiquity, we”ll use its implementation in this tutorial.


    Making Promises with $.Deferred

    Every jQuery Promise begins with a Deferred. A Deferred is just a Promise with methods that allow its owner to resolve or reject it. All other Promises are “read-only” copies of a Deferred; we’ll talk about those in the next section. To create a Deferred, use the $.Deferred() constructor:

    A Deferred is just a Promise with methods that allow its owner to resolve or reject it.

    var deferred = new $.Deferred();
    
    deferred.state();  // "pending"
    deferred.resolve();
    deferred.state();  // "resolved"
    deferred.reject(); // no effect, because the Promise was already resolved
    

    (Version note: state() was added in jQuery 1.7. In 1.5/1.6, use isRejected() and isResolved().)

    We can get a “pure” Promise by calling a Deferred’s promise() method. The result is identical to the Deferred, except that the resolve() and reject() methods are missing.

    var deferred = new $.Deferred();
    var promise = deferred.promise();
    
    promise.state();  // "pending"
    deferred.reject();
    promise.state();  // "resolved"
    

    The promise() method exists purely for encapsulation: If you return a Deferred from a function, it might be resolved or rejected by the caller. But if you only return the pure Promise corresponding to that Deferred, the caller can only read its state and attach callbacks. jQuery itself takes this approach, returning pure Promises from its AJAX methods:

    var gettingProducts = $.get("/products");
    
    gettingProducts.state();  // "pending"
    gettingProducts.resolve;  // undefined
    

    Using the -ing tense in the name of a Promise makes it clear that it represents a process.


    Modeling a UI Flow With Promises

    Once you have a Promise, you can attach as many callbacks as you like using the done(), fail(), and always() methods:

    promise.done(function() {
      console.log("This will run if this Promise is resolved.");
    });
    
    promise.fail(function() {
      console.log("This will run if this Promise is rejected.");
    });
    
    promise.always(function() {
      console.log("And this will run either way.");
    });
    

    Version Note: always() was referred to as complete() before jQuery 1.6.

    There’s also a shorthand for attaching all of these types of callbacks at once, then():

    promise.then(doneCallback, failCallback, alwaysCallback);
    

    Callbacks are guaranteed to run in the order they were attached in.

    One great use case for Promises is representing a series of potential actions by the user. Let’s take a basic AJAX form, for example. We want to ensure that the form can only be submitted once, and that the user receives some acknowledgement when they submit the form. Furthermore, we want to keep the code describing the application’s behavior separate from the code that touches the page’s markup. This will make unit testing much easier, and minimize the amount of code that needs to be changed if we modify our page layout.

    // Application logic
    var submittingFeedback = new $.Deferred();
    
    submittingFeedback.done(function(input) {
      $.post("/feedback", input);
    });
    
    // DOM interaction
    $("#feedback").submit(function() {
      submittingFeedback.resolve($("textarea", this).val());
    
      return false;  // prevent default form behavior
    });
    submittingFeedback.done(function() {
      $("#container").append("<p>Thank you for your feedback!</p>");
    });
    

    (We’re taking advantage of the fact that arguments passed to resolve()/reject() are forwarded verbatim to each callback.)


    Borrowing Promises From the Future

    pipe() returns a new Promise that will mimic any Promise returned from one of the pipe() callbacks.

    Our feedback form code looks good, but there’s room for improvement in the interaction. Rather than optimistically assuming that our POST call will succeed, we should first indicate that the form has been sent (with an AJAX spinner, say), then tell the user whether the submission succeeded or failed when the server responds.

    We can do this by attaching callbacks to the Promise returned by $.post. But therein lies a challenge: We need to manipulate the DOM from those callbacks, and we’ve vowed to keep our DOM-touching code out of our application logic code. How can we do that, when the POST Promise is created within an application logic callback?

    A solution is to “forward” the resolve/reject events from the POST Promise to a Promise that lives in the outer scope. But how do we do that without several lines of bland boilerplate (promise1.done(promise2.resolve);…)? Thankfully, jQuery provides a method for exactly this purpose: pipe().

    pipe() has the same interface as then() (done() callback, reject() callback, always() callback; each callback is optional), but with one crucial difference: While then() simply returns the Promise it’s attached to (for chaining), pipe() returns a new Promise that will mimic any Promise returned from one of the pipe() callbacks. In short, pipe() is a window into the future, allowing us to attach behaviors to a Promise that doesn’t even exist yet.

    Here’s our new and improved form code, with our POST Promise piped to a Promise called savingFeedback:

    // Application logic
    var submittingFeedback = new $.Deferred();
    var savingFeedback = submittingFeedback.pipe(function(input) {
      return $.post("/feedback", input);
    });
    
    // DOM interaction
    $("#feedback").submit(function() {
      submittingFeedback.resolve($("textarea", this).val());
    
      return false;  // prevent default form behavior<br/>
    });
    
    submittingFeedback.done(function() {
      $("#container").append("<div class="spinner">");
    });
    
    savingFeedback.then(function() {
      $("#container").append("<p>Thank you for your feedback!</p>");
    }, function() {
      $("#container").append("<p>There was an error contacting the server.</p>");
    }, function() {
      $("#container").remove(".spinner");
    });
    

    Finding the Intersection Of Promises

    Part of the genius of Promises is their binary nature. Because they have only two eventual states, they can be combined like booleans (albeit booleans whose values may not yet be known).

    The Promise equivalent of the logical intersection (AND) is given by $.when(). Given a list of Promises, when() returns a new Promise that obeys these rules:

    1. When all of the given Promises are resolved, the new Promise is resolved.
    2. When any of the given Promises is rejected, the new Promise is rejected.

    Any time you’re waiting for multiple unordered events to occur, you should consider using when().

    Simultaneous AJAX calls are an obvious use case:

    $("#container").append("<div class='spinner'>");
    $.when($.get("/encryptedData"), $.get("/encryptionKey")).then(function() {
      // both AJAX calls have succeeded
    }, function() {
      // one of the AJAX calls has failed
    }, function() {
      $("#container").remove(".spinner");
    });
    

    Another use case is allowing the user to request a resource that may or may not have already be available. For example, suppose we have a chat widget that we’re loading with YepNope (see Easy Script Loading with yepnope.js)

    var loadingChat = new $.Deferred();
    yepnope({
      load: "resources/chat.js",
      complete: loadingChat.resolve
    });
    
    var launchingChat = new $.Deferred();
    $("#launchChat").click(launchingChat.resolve);
    launchingChat.done(function() {
      $("#chatContainer").append("<div class='spinner'>");
    });
    
    $.when(loadingChat, launchingChat).done(function() {
      $("#chatContainer").remove(".spinner");
      // start chat
    });
    

    Conclusion

    Promises have proven themselves to be an indispensable tool in the ongoing fight against async spaghetti code. By providing a binary representation of individual tasks, they clarify application logic and cut down on state-tracking boilerplate.

    If you’d like to know more about Promises and other tools for preserving your sanity in an ever more asynchronous world, check out my upcoming eBook: Async JavaScript: Recipes for Event-Driven Code (due out in March).


  • Tue, 21 Feb 2012 17:41:02 +0000: PDO vs. MySQLi: Which Should You Use? - Nettuts+

    When accessing a database in PHP, we have two choices: MySQLi and PDO. So what should you know before choosing one? The differences, database support, stability, and performance concerns will be outlined in this article.


    Summary

    PDO MySQLi
    Database support 12 different drivers MySQL only
    API OOP OOP + procedural
    Connection Easy Easy
    Named parameters Yes No
    Object mapping Yes Yes
    Prepared statements
    (client side)
    Yes No
    Performance Fast Fast
    Stored procedures Yes Yes

    Connection

    It’s a cinch to connect to a database with both of these:

    // PDO
    $pdo = new PDO("mysql:host=localhost;dbname=database", 'username', 'password');
    
    // mysqli, procedural way
    $mysqli = mysqli_connect('localhost','username','password','database');
    
    // mysqli, object oriented way
    $mysqli = new mysqli('localhost','username','password','database');
    	

    Please note that these connection objects / resources will be considered to exist through the rest of this tutorial.


    API Support

    Both PDO and MySQLi offer an object-oriented API, but MySQLi also offers a procedural API – which makes it easier for newcomers to understand. If you are familiar with the native PHP MySQL driver, you will find migration to the procedural MySQLi interface much easier. On the other hand, once you master PDO, you can use it with any database you desire!


    Database Support

    The core advantage of PDO over MySQLi is in its database driver support. At the time of this writing, PDO supports 12 different drivers, opposed to MySQLi, which supports MySQL only.

    To print a list of all the drivers that PDO currently supports, use the following code:

    var_dump(PDO::getAvailableDrivers());

    What does this mean? Well, in situations when you have to switch your project to use another database, PDO makes the process transparent. So all you’ll have to do is change the connection string and a few queries – if they use any methods which aren’t supported by your new database. With MySQLi, you will need to rewrite every chunk of code – queries included.


    Named Parameters

    This is another important feature that PDO has; binding parameters is considerably easier than using the numeric binding:

    $params = array(':username' => 'test', ':email' => $mail, ':last_login' => time() - 3600);
    
    $pdo->prepare('
    	SELECT * FROM users
    	WHERE username = :username
    	AND email = :email
    	AND last_login > :last_login');
    
    $pdo->execute($params);

    …opposed to the MySQLi way:

    $query = $mysqli->prepare('
    	SELECT * FROM users
    	WHERE username = ?
    	AND email = ?
    	AND last_login > ?');
    
    $query->bind_param('sss', 'test', $mail, time() - 3600);
    $query->execute();

    The question mark parameter binding might seem shorter, but it isn’t nearly as flexible as named parameters, due to the fact that the developer must always keep track of the parameter order; it feels “hacky” in some circumstances.

    Unfortunately, MySQLi doesn’t support named parameters.


    Object Mapping

    Both PDO and MySQLi can map results to objects. This comes in handy if you don’t want to use a custom database abstraction layer, but still want ORM-like behavior. Let’s imagine that we have a User class with some properties, which match field names from a database.

    class User {
    	public $id;
    	public $first_name;
    	public $last_name;
    
    	public function info()
    	{
    		return '#'.$this->id.': '.$this->first_name.' '.$this->last_name;
    	}
    }

    Without object mapping, we would need to fill each field’s value (either manually or through the constructor) before we can use the info() method correctly.

    This allows us to predefine these properties before the object is even constructed! For isntance:

    $query = "SELECT id, first_name, last_name FROM users";
    
    // PDO
    $result = $pdo->query($query);
    $result->setFetchMode(PDO::FETCH_CLASS, 'User');
    
    while ($user = $result->fetch()) {
    	echo $user->info()."\n";
    }
    // MySQLI, procedural way
    if ($result = mysqli_query($mysqli, $query)) {
    	while ($user = mysqli_fetch_object($result, 'User')) {
    		echo $user->info()."\n";
    	}
    }
    // MySQLi, object oriented way
    if ($result = $mysqli->query($query)) {
    	while ($user = $result->fetch_object('User')) {
    		echo $user->info()."\n";
    	}
    }
    


    Security

    Both libraries provide SQL injection security, as long as the developer uses them the way they were intended (read: escaping / parameter binding with prepared statements).

    Lets say a hacker is trying to inject some malicious SQL through the ‘username’ HTTP query parameter (GET):

    $_GET['username'] = "'; DELETE FROM users; /*"

    If we fail to escape this, it will be included in the query “as is” – deleting all rows from the users table (both PDO and mysqli support multiple queries).

    // PDO, "manual" escaping
    $username = PDO::quote($_GET['username']);
    
    $pdo->query("SELECT * FROM users WHERE username = $username");
    
    // mysqli, "manual" escaping
    $username = mysqli_real_escape_string($_GET['username']);
    
    $mysqli->query("SELECT * FROM users WHERE username = '$username'");
    

    As you can see, PDO::quote() not only escapes the string, but it also quotes it. On the other side, mysqli_real_escape_string() will only escape the string; you will need to apply the quotes manually.

    // PDO, prepared statement
    $pdo->prepare('SELECT * FROM users WHERE username = :username');
    $pdo->execute(array(':username' => $_GET['username']));
    
    // mysqli, prepared statements
    $query = $mysqli->prepare('SELECT * FROM users WHERE username = ?');
    $query->bind_param('s', $_GET['username']);
    $query->execute();
    

    I recommend that you always use prepared statements with bound queries instead of PDO::quote() and mysqli_real_escape_string().


    Performance

    While both PDO and MySQLi are quite fast, MySQLi performs insignificantly faster in benchmarks – ~2.5% for non-prepared statements, and ~6.5% for prepared ones. Still, the native MySQL extension is even faster than both of these. So if you truly need to squeeze every last bit of performance, that is one thing you might consider.


    Summary

    Ultimately, PDO wins this battle with ease. With support for twelve different database drivers (eighteen different databases!) and named parameters, we can ignore the small performance loss, and get used to its API. From a security standpoint, both of them are safe as long as the developer uses them the way they are supposed to be used (read: prepared statements).

    So if you’re still working with MySQLi, maybe it’s time for a change!


  • Mon, 20 Feb 2012 22:15:58 +0000: The Largest jQuery Class in the World - Nettuts+

    A couple weeks ago, Tuts+ Premium launched a free new real-time course, called “30 Days to Learn jQuery.” After signing up, each member receives an email, linking to a new video lesson for an entire month.

    I’m pleased to announce that, after only two weeks into the course, we’ve amassed the largest jQuery class in the world, with 40,000 registered students!


    You Can Still Sign Up

    If you never got around to signing up for the course, you still can; there’s no deadline. Even after I publish the final “Lesson 30,” the course will continue to be freely available forever.

    The Largest jQuery Class in the World

    For those of you who have some experience with jQuery, the final two weeks of the course will focus on higher level concepts, such as templating, code organization, deferreds, and much more. It’s okay to jump ahead, if you already know the essentials!


  • Sat, 18 Feb 2012 14:39:54 +0000: Nettuts+ Quiz #10: Basic CSS3 Techniques - Nettuts+

    In 2012, we plan to take our quizzes to a whole new level with ones aimed at all languages and catering to all competencies and tastes. This month, we’re covering some basic concepts and techniques in CSS3.

    The prime focus today is on the easier, more accessible portions of CSS3. If you’re a hardcore CSS3 fan, don’t worry — transitions, animations, gradients and media queries are on the way!




  • Thu, 16 Feb 2012 22:39:21 +0000: How to Upload Files with Ease Using DragonFly: New on Premium - Nettuts+

    File uploads are generally a tricky area in web development. In this Tuts+ Premium tutorial, we will learn how to use Dragonfly, a powerful Ruby gem that makes it easy and efficient to add any kind of upload functionality to a Rails project.

    Become a Premium member to read this tutorial, as well as hundreds of other advanced tutorials and screencasts from the Tuts+ network.


    What We’re Going to Build

    Our sample application will display a list of users, and for each one of them, we will be able to upload an avatar and have it stored. Additionally, Dragonfly will allow us to:

    • Dynamically manipulate images without saving additional copies
    • Leverage HTTP caching to optimize our application load

    Additionally, in this lesson, we will follow a BDD [Behavior Driven Development] approach, using Cucumber and RSpec.


    Tuts+ Premium

    The recently re-launched Tuts+ Premium is a service that provides top-tier training in a variety of creative fields. Whether you prefer books, visual training, or in depth tutorials, we have you covered. While we unfortunately can’t afford to provide the service for free, it’s only $19 a month – less than you’d spend on dinner.

    I hope you’ll consider checking it out! In addition to learning a huge variety of new skills, it’s also a fantastic way to say thank you to Nettuts+.



smashingapps.com
  • Wed, 22 Feb 2012 04:42:24 +0000: 6 Useful And Free Password Management Tools - Free and Useful Online Resources for Designers and Developers
    Many people find it difficult to remember passwords. For them it is just the most difficult task to accomplish and therefore they need some help or some tool that they can use to manage their passwords safely. Passwords are the key to every important service that you use either on the web or in your real world, and they cannot be compromised. On the other hand, remembering different passwords for the different services is not an easy thing.

  • Mon, 20 Feb 2012 17:29:04 +0000: 40+ High Quality And Free Web Templates In PSD - Free and Useful Online Resources for Designers and Developers
    Finding out high quality and premium PSD files is extremely difficult but keeping them in the toolbox is tremendously important for the web designers because such PSD files always come in handy and save loads of time. There are so many resources available on the net you can get freebie PSD files from but not all of them are of good quality. On the other hand, some web resources offer premium membership so that you can get some high quality and creative PSD web templates but this comes for a price.

  • Thu, 16 Feb 2012 22:43:03 +0000: 17 Beautiful Free Floral Pattern Sets - Free and Useful Online Resources for Designers and Developers
    Are you looking for some cool and appealing pattern collections? If yes, then look no further, this article is just for you! Here we are showcasing some free to use Floral pattern collections that will help you making your art works look even more appealing and tempting. You can utilize these floral patterns depending on your style and your design concept. We hope that you can find some good options for your next project. Enjoy checking out this compilation and have more fun in utilizing them for your works. Enjoy!

  • Wed, 15 Feb 2012 18:18:59 +0000: 17 Adobe Flash Tutorials For Creating Menus And Navigations - Free and Useful Online Resources for Designers and Developers
    The navigation and the menus of a website need to be easy to use as well as pleasant enough that user will like it. This is how you can define a user friendly website. For better and impressive navigation and menu, you can take the help of Adobe Flash. Thus, keeping this in mind we have put together a collection of some useful Adobe Flash tutorials for creating menus and navigations.

  • Tue, 14 Feb 2012 17:39:53 +0000: 15 Excellent Tools For Profiling Your Websites Speed - Free and Useful Online Resources for Designers and Developers
    Today, we present an interesting showcase of some amazing and extraordinary tools that you can use for profiling your website speed. This is especially important because we all know that an Internet user is very impatient in waiting for a web page to load. Therefore, it is extremely crucial that you check your website performance as well as its capability to render speedily. These are the decisive factors for the usability and ultimately for the success of a website.

Did you like this? If so, please bookmark it,
tell a friend
about it, and subscribe to the blog RSS feed.