PHP
  Home arrow PHP arrow Page 3 - Adding Methods to the Query Processor in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Adding Methods to the Query Processor in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2006-05-24


    Table of Contents:
  • Adding Methods to the Query Processor in PHP
  • Reviewing previous PHP networking functions: a quick look at the "QueryProcessor" class
  • Adding more functionality to the "QueryProcessor" class: defining the "Ping()" and "IpConfig()" methods
  • More methods ahead: defining the "Netstat()" and "getMXRecordsWin()" methods
  • Gluing the pieces together: listing the full source code of the "QueryProcessor" class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Adding Methods to the Query Processor in PHP - Adding more functionality to the "QueryProcessor" class: defining the "Ping()" and "IpConfig()" methods
    ( Page 3 of 5 )

    The first method that I will add to the class is "IpConfig()," which, as the name clearly suggests, is responsible for executing the "ipconfig" Windows-based utility. In case you didn't know, this program will let you know the network settings of your Windows system, including the IP address, subnet mask, DNS suffixes, default gateway, and so on for each of the network adapters installed on your computer.

    Having described the functionality of the "ipconfig" Windows utility, take a look at the method below, which runs this command on a Windows machine:

    // execute 'ipconfig' command on Windows systems
    public function IpConfig(){
        $output='Running ipconfig command...Please wait.<br />';
        exec('ipconfig',$lines);
        foreach($lines as $line){
            $output.=$line.'<br />';
        }
        return $output;
    }

    In this case, the above "Ipconfig()" method uses the "exec()" PHP built-in function, in order to perform the homonymous Windows utility. As you know, this function allows the execution of commands on the server (provided that you have the right permissions) and returns the corresponding results as an array structure.

    After executing the "ipconfig" command, the output is returned to calling code, simply by iterating over the output array returned by the "exec()" function. Evidently, this method is really simple to read and code, thus I'll move on to the next one, "Ping()," which runs the popular "ping" command on Windows-based systems. Please take a look at the way this method is defined:

    // execute 'ping' command on Windows systems
    public function Ping(){
        $output='Running ping command...Please wait.<br />';
        exec('ping '.$this->host,$lines);
        foreach($lines as $line){
            $output.=$line.'<br />';
        }
        return $output;
    }

    As illustrated in the above code block, the "Ping()" method looks nearly identical to the previous one. Of course, the only difference rests on the type of Window command executed, which in this case is the famous "ping" utility. Similar to the "IpConfig()" method that you learned before, this method first uses the "exec()" PHP function, in order to run the "ping" program, and next returns the result as an array.

    Due to the numerous similarities exposed by the two methods, it's possible to merge them into one and avoid writing additional code. However, I want you to learn each method as a separate block of code, since it's much simpler to read and understand.

    Now, after defining the prior methods, I'll code two new methods in the next section, which also use the "exec()" PHP native function for doing its business on Windows systems. To learn more on this please keep on reading.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek