Jump to content

Acs

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by Acs

  1. Stupid edit timer!! The xmlcreate is just a simple method to create a dom object and then create an xml file public static function xmlcreate($file,$root = "root") { $dom = new DOMDocument('1.0', 'utf-8'); $element = $dom->appendChild(new DOMElement($root)); $xml = $dom->saveXML(); file_put_contents($file,$xml); return $xml; }
  2. This is from my xml helper class. Try it and let me know if it works public static function arraytoxml(array $data,$file,$elementname = "items") { $xml = simplexml_load_string(self::xmlcreate($file)); //we will always create the file if (!isset($xml->$elementname)) $xml->addChild($elementname); //Now let's add the data self::_arraytoxml($xml->$elementname,$data); //print_r($xml); return self::xmltofile($xml,$file); } // /** * This is what really creates the array * I had to seperate it so that I could use recursion * The values of the array, might be values them selfves * * @param SimpleXMLElement $xml * @param mixed $data */ private static function _arraytoxml(SimpleXMLElement &$xml,$data) { foreach ($data as $k => $value) { if (is_numeric($k)) $k = "_" . $k . "_"; //xml does not allow elements to just be numeric if (!isset($xml->$k)) $xml->addChild($k); if (is_array($value)) self::_arraytoxml($xml->$k,$value); else $xml->$k = self::xmlCdata($value); } }
  3. Doesn't php have a filter email validator function?
  4. If you really want to make a treeview like in windows explorer you have to know a bit about javascript. Your best bet is to try and use something already made.
  5. Try removing the ` ` from the field's list enrol (title,first_name,last_name)
  6. Ok ok I think I get what you're saying. Mine don't work like that, but maybe they will Thanks
  7. But my idea of model is not one model for every row. And if you have more stuff to update, delete etc you just do one thing then save then do the other than save.
  8. When you have the code the way you want it, start using xdebug to see bottlenecks etc
  9. Why would you want to load 5 models of the same type?
  10. I don't understand your question. What do you mean by 5 users in the controller? Did you mean models?
  11. In my framework I do: $this->loadmodel("teste"); To load the teste model and then I access/change this way: //create new stuff $this->teste->texto = "uuuuuu"; $this->teste->contador = 111; $this->teste->save(); $this->loadmodel("counter"); $this->counter->fetch_counter(); echo "Values -> " , $this->counter->counter++ , "<br>"; echo "Values -> " , $this->counter->counter; $this->counter->save(); One thing I would like to know is how are you implementing those add_javascript and add_css functions? Are you just replacing the head with <head><style> etc... and doing the same for the </body> tag with the javascript function?
  12. Nice.. You don't comment on code but when the topic is a about a framework you comment about the layout of the author's website... really nice I am also on a 22' monitor and I have no problem with it. The image is nice.
  13. Cool! I hope my framework also changes the way people use websites I will try to show a beta version in the near future And by the way, what is powering your xeoncross site? Codeigniter?
  14. If you know how to improve code you see you should!
  15. That wouldn't work because those have nothing to do with the parameters names. Those are private properties that have the same names as the parameters in the __construct() Also a note from the manual: Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster. And the & to have the reference is not necessary $db =& new Mysql()
  16. I remember that there is somewhere in the config js file of fck that you can change from <p> to <br> maybe that has something to do with it
  17. Acs

    PDO speed

    Indeed it was my code! I removed a loop and the pdo statements were a lot faster, just take a look. These are 10 executions of my framework using pdo statements to insert data on a mysql table: Date Time;Milliseconds;Memory (in bytes) 2008/10/14 21:50:50;0.0235240459442;143960 2008/10/14 21:50:50;0.0313630104065;143960 2008/10/14 21:50:50;0.0313642024994;143960 2008/10/14 21:50:50;0.0235631465912;143960 2008/10/14 21:50:50;0.0219089984894;143960 2008/10/14 21:50:50;0.0220711231232;143960 2008/10/14 21:50:50;0.0247020721436;143960 2008/10/14 21:50:50;0.022469997406;143960 2008/10/14 21:50:50;0.0220470428467;143960 2008/10/14 21:50:50;0.0223350524902;143960 These are 10 executions of my framework using pdo with the query method and one big query: Date Time;Milliseconds;Memory (in bytes) 2008/10/14 22:01:20;0.0519180297852;143464 2008/10/14 22:01:21;0.0859501361847;143464 2008/10/14 22:01:21;0.060604095459;143464 2008/10/14 22:01:21;0.0527191162109;143464 2008/10/14 22:01:21;0.0556530952454;143464 2008/10/14 22:01:21;0.0505831241608;143464 2008/10/14 22:01:21;0.128275156021;143464 2008/10/14 22:01:21;0.0642030239105;143464 2008/10/14 22:01:21;0.0600869655609;143464 2008/10/14 22:01:21;0.0702891349792;143464 I used again ab with -100 (I just used -n because -c seems to produce a strange behavior) but I just show the 10 first of each and you can see quite clearly the pdo statements, after I refined the code, is the fastest Hope this can help someone decide with either going with pdo statements or queries. The only downside now is it, is using a bit more memory than the query method, but I will try to improve on that. Note: I am not using bindParam anymore. I just passed the values to be replaced in the execute method. Going to try the beginTransaction method to see how it handles 100 executions
  18. Acs

    PDO speed

    I am going to try to eliminate some of the loops and I will then check the speeds. This might be just about the loops I have in.
  19. Acs

    PDO speed

    Well.. it says it the manual: "Calling PDO::prepare() and PDOStatement::execute() for statements that will be issued multiple times with different parameter values optimizes the performance of your application" But I guess it really depends on the situation, because I just create all the insert statements in the same var and do a query with that
  20. Acs

    PDO speed

    For the pdo statements I have to loop every item in the array and because it's an array of array's I have to loop that too. Ok maybe the problem is there, so many loops, but there is no other way to do this. After re-reading your question: I used ab to load the page 100 times and concurrency of 50
  21. Acs

    PDO speed

    It's part of my implementation of the activerecord pattern so it might not make sense. $query = "INSERT INTO " . $this->_tablename . "(" . $this->_fieldsNames . ") VALUES("; foreach ($this->_insert_data as $k => $data) { //This->_insert_data is an array containing (fieldname => "value" $bigquery .= $query; $values = array(); foreach ($data as $value) $values[] = (is_string($value)) ? "'$value'" : $value; $bigquery .= implode(",",$values); $bigquery .= ");"; } $this->_insert_data = null; try { if ($this->conn->exec($bigquery)) return true; else { print_r($this->conn->errorInfo()); } } catch (PDOException $e) { throw new acs_exception($e); exit(); } This uses the prepared statements: try { $prepared_query = "INSERT INTO " . $this->_tablename . "(" . $this->_fieldsNames . ") VALUES("; $prepared_query_values = str_replace(",",",:",":" . $this->_fieldsNames); $prepared_query .= $prepared_query_values . ")"; //echo $prepared_query , "<br>"; $pdo_preObj = $this->conn->prepare($prepared_query); foreach ($this->_insert_data as $k => $data) { foreach ($data as $fieldtoaddName => $fieldtoaddValue) { //echo "var name - " , $fieldtoaddName , " -- var value - " , $fieldtoaddValue , "<br>"; $$fieldtoaddName = $fieldtoaddValue; //if (!$pdo_preObj->bindValue(':' . $fieldtoaddName,$fieldtoaddValue)) if (!$pdo_preObj->bindParam(':' . $fieldtoaddName,$fieldtoaddValue)) throw new acs_exception("No bind"); } //echo "<pre>"; if ($pdo_preObj->execute()) echo "yuupi"; else print_r($pdo_preObj->errorInfo()); } } catch (PDOException $e) { throw new acs_exception($e); exit(); } Here is the data in the array: Array ( [0] => Array ( [texto] => uuuuuu [contador] => 111 ) [1] => Array ( [texto] => uuuuuu2 [contador] => 2 ) [2] => Array ( [texto] => uuuuuu3 [contador] => 3 ) [3] => Array ( [texto] => uuuuuu4 [contador] => 4 ) [4] => Array ( [texto] => uuuuuu5 [contador] => 5 ) [5] => Array ( [texto] => uuuuuu6 [contador] => 6 ) [6] => Array ( [texto] => uuuuuu7 [contador] => 7 ) [7] => Array ( [texto] => uuuuuu8 [contador] => 8 ) )
  22. Acs

    PDO speed

    bump again - Maybe this should be moved to another section!!
×
×
  • 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.