Jump to content

Recommended Posts

Hi,

 

1. What is the use of iterator SPL  since we can use while loop, foreach and for loop?

    I can't find its useful usage for me. can you give me an example?

 

2. Mysql is opensource?

    if I used it to create a system using php and mysql and sell it to others. Do I need to pay for that?

 

3. Stored procedure is better?

    I have look in the sourcecode and I found that my friend was using stored procedure.

    As they told me stored procedure is save server memory for running millions of query.

    but the cons is they are hard to maintain. Is that true?

 

4. My friends was using prostgre sql integrate with c language.

    he said that will be faster compare to just use php and mysql.

    Is that true? Is there any way to integrate mysql with c?

    or I can use php integrate with c. will it faster compare to

    postgresql with c?

 

5. what is the best/stable free c/c++ compiler and can use with apache, php and mysql server?

    g++?

 

 

1. What is the use of iterator SPL  since we can use while loop, foreach and for loop?

    I can't find its useful usage for me. can you give me an example?

 

class MyIterator implements Iterator, Countable {
  private $key = 0;
  private $count = 0;
  private $data = array();
  
  public function __construct($data) { $this->data = $data; $this->count = sizeof($data); }
  public function rewind() { $this->key = 0; }
  public function valid() { return $this->key < $this->count; }
  public function next() { ++$this->key; }
  public function current() { return $this->data[$this->key]; }
  public function key() { return $this->key; }
  public function count() { return $this->count; }
}

 

2. Mysql is opensource?

    if I used it to create a system using php and mysql and sell it to others. Do I need to pay for that?

 

Yes. No.

 

3. Stored procedure is better?

    I have look in the sourcecode and I found that my friend was using stored procedure.

    As they told me stored procedure is save server memory for running millions of query.

    but the cons is they are hard to maintain. Is that true?

 

A stored procedure will not save server memory as when it returns a result it still has to be loaded in to memory for PHP to process it.

 

4. My friends was using prostgre sql integrate with c language.

    he said that will be faster compare to just use php and mysql.

    Is that true? Is there any way to integrate mysql with c?

    or I can use php integrate with c. will it faster compare to

    postgresql with c?

 

C is indeed faster then PHP, PHP is build on top of C so it's slightly slower.

 

5. what is the best/stable free c/c++ compiler and can use with apache, php and mysql server?

    g++?

 

G++ is a language not a compiler. Here is a list of compilers http://www.thefreecountry.com/compilers/cpp.shtml, please note you should use the appropriate compiler for your operating system.

1. What is the use of iterator SPL  since we can use while loop, foreach and for loop?

    I can't find its useful usage for me. can you give me an example?

 

The SPL comes in very handy once you start delving into the object-oriented way of thinking/coding. As an example, here are two ways of traversing the files in a directory:

 

$dir = opendir('/path/to/some/dir');
while (($file = readdir($dir)) !== false) {
    echo "filename: $file : filetype: " . filetype('/path/to/some/dir/' . $file) . "\n";
}
closedir($dir);

 

$dir = new FilesystemIterator('/path/to/some/dir');
foreach ($dir as $fileinfo) {
    echo "filename: " . $fileinfo->getFilename() . " : filetype: " . $fileinfo->getType() . "\n";
}

 

With the iterator there, we could very easily filter the results to show only files, files above a certain size, the first n files, files ordered by size, etc. by only changing the first line of code. With the opendir snippet, those things wouldn't be quite so neat and tidy.

5. what is the best/stable free c/c++ compiler and can use with apache, php and mysql server?

    g++?

 

G++ is a language not a compiler. Here is a list of compilers http://www.thefreecountry.com/compilers/cpp.shtml, please note you should use the appropriate compiler for your operating system.

 

What are you talking about? g++ is a C++ compiler.

5. what is the best/stable free c/c++ compiler and can use with apache, php and mysql server?

    g++?

 

G++ is a language not a compiler. Here is a list of compilers http://www.thefreecountry.com/compilers/cpp.shtml, please note you should use the appropriate compiler for your operating system.

 

What are you talking about? g++ is a C++ compiler.

 

I see now, I had mistaken it for Go.

I saw sample of Iterator code on php.net

 

class MyIterator implements Iterator
{
    private $var = array();

    public function __construct($array)
    {
        if (is_array($array)) {
            $this->var = $array;
        }
    }


    public function current() {
        $var = current($this->var);
        echo "current: $var<br />";
        return $var;
    }

    
    public function rewind() {
        echo "rewinding<br />";
        reset($this->var);
    }

    public function key() {
        $var = key($this->var);
        echo "key: $var<br />";
        return $var;
    }

    public function next() {
        $var = next($this->var);
        echo "next: $var<br />";
        return $var;
    }

    public function valid() {
        $var = $this->current() !== false;
        echo "valid: {$var}<br />";
        return $var;
    }
}

class MyCollection implements IteratorAggregate
{
    private $items = array();
    private $count = 0;

    // Required definition of interface IteratorAggregate
    public function getIterator() {
        return new MyIterator($this->items);
    }

    public function add($value) {
        $this->items[$this->count++] = $value;
    }
}

$coll = new MyCollection();
$coll->add('value 1');
$coll->add('value 2');
$coll->add('value 3');

foreach ($coll as $key => $val) {
    echo "key/value: [$key -> $val]<br /><br />";
}

 

With another sample I create:

$testArray = array('value 1', 'value 2', 'value 3');
$first = 0;
define("breakline", "<br />");
echo '-------------------------------------------------'.breakline;
foreach($testArray as $key => $value){
    if($first == 0){
        echo 'rewinding'.breakline;
        $first = 1;
    }
    echo 'current: '.$value.breakline;
    echo 'valid: ';
    echo ($value)?1:0;
    echo breakline;
    echo 'current: '.$value.breakline;
    echo 'key: '.$key.breakline;
    echo 'key/value: ['.$key.' -> '.$value.']'.breakline;
    echo breakline;
}
echo 'next: '.breakline;
echo 'current: '.breakline;
echo 'valid: '.breakline;

 

I can not see the advantage of using Iterator.

 

Please advices

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.