Jump to content

sequalit

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sequalit's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. At first I didn't think PHP could do half the stuff it can, such as write and read files and such. The more I learn about PHP the more I see its just like any other OO-Programming language out there, and can do all the same stuff, only difference is you have to run a apache server and a web browser haha
  2. Is this secure? Technically anything other than letters and numbers should throw it off right? if(!ctype_alnum($_POST['username'])){ die('hey a hacker!'); }else{ $result = mysql_query(sprintf("SELECT * FROM users WHERE username='%s'", $_POST['username']) }
  3. why do you have a while loop for the images?
  4. you can write the code to a file and then include('/path/to/filename');
  5. Think you better start working on it In my opinion, anybody would be crazy to do that for you... Whats the point in learning PHP if you're not willing to fork over the brain cells? Some hints though: the links are using AJAX
  6. Won't let me edit post for some odd reason? Anways, a couple of changes Change all instancse of $_SESSION to $GLOBALS - better place to store it. And in the echoAll() class, change this line echo $message[1]."<br>"; to this echo "Message $i: ".$message[1]."<br>";
  7. Ever look at your code and you have a million echo statements throughout your code, and some are commented out others are not, and you used these echo's to help you debug your application during development? I wrote a simple class to help with debugging! With this class you will never have to uncomment your echo statements again! Just tell the debugger class to not display those messages! Its awesome! I'm sure this could use some work to be made even cooler Please give any idea's or suggestions you have so that I can make this cooler If you add something to it, please let me know in this post, so I can merge it into the official class Where would be the best place to store this? I choose $_SESSION because thats the only place i know of to put it! Debugger Source, version 1 /** * Copyright (c) 2008 Thadeus N. Burgess (thadeus.burgess(at)gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * define("ECHOS", true); define("ECHO_SEPERATOR", "~|~"); define("debugger", "Debugger"); /** * Class to handle echo messages used for debugging during development process */ class Debugger{ private $echos; private $echoPages; /** * Constructor. * If ECHOS true then we set up the arrays */ function Debugger(){ if(ECHOS){ //if echos is off, we do nothing, to save memory $this->echos = array(); $this->echoPages = array(); } } /** * Mark page to be echo'ed * * @param string $page Name of message to be echo'ed EX. 'index.php', 'mysql.class', 'foo.function' * * @return void */ function setDoEcho($page){ if(ECHOS) //if echos is off, we do nothing, to save memory array_push($this->echoPages, $page); } /** * Register message to be echo'ed * * @param string $page Name of message to be echo'ed EX. 'index.php', 'mysql.class', 'foo.function' * @param string $message Message that will be echo'ed * * @return void */ function registerEcho($page, $message){ if(ECHOS) //if echos is off, we do nothing, to save memory array_push($this->echos, $page.ECHO_SEPERATOR.$message); } /** * Echo all messages that have been set to echo */ function echoAll(){ if(ECHOS)//if echos is off, we do nothing, to save memory for($i=0;$i<count($this->echos);$i++){ $message = explode(ECHO_SEPERATOR, $this->echos[$i]); if(in_array($message[0], $this->echoPages))// if we have set it to be echo'ed, echo it echo $message[1]."<br>"; } echo "<br><br><br>"; } } HOW TO USE: index.php require_once('debugger.php'); $_SESSION[debugger] = new Debugger(); // we set it in session so that everything can access it if(ECHOS){ //All you have to do now is comment these out to not display //a module!!! How awesome!! //examples $_SESSION[debugger]->setDoEcho('database.php'); $_SESSION[debugger]->setDoEcho('doSomething.function'); $_SESSION[debugger]->setDoEcho('a_thing.class'); $_SESSION[debugger]->setDoEcho('mysql.class'); $_SESSION[debugger]->setDoEcho('hello.world'); $_SESSION[debugger]->echoAll();// echo all messages in order } Then anywhere you want an echo do this $message = "Hello World"; $_SESSSION[debugger]->registerEcho('hello.world', $message); Turn This function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; //echo "<br>QUERYING"; //echo "<br>". $this->query; $this->res = mysql_query($sql, $this->con); //echo "<br>RESULTS: ".$this->res."<br>"; //return new results($this->res); } Into This: function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); if(!$this->res) $this->queryError(); $_SESSION[debugger]->registerEcho('mysql.class', "QUERYING: ".$this->query); $_SESSION[debugger]->registerEcho('mysql.class', "RESULTS: ".$this->res); }
  8. Thank you dbo and 448191 I ended up looking at both for examples and idea's and built my own I now have a great MVC template system that I LOVE!!!! It's so awesome, works great! I love you guys ;p
  9. Average Time of PHP Completion (100 results) :0.00052145242691 Average Time of QRY Completion (100 results) :0.000961785316467 PHP faster by :0.000333070755005 0.00061297416687 - 0.000946044921875 PHP faster by :0.000367879867554 0.000465154647827 - 0.000833034515381 PHP faster by :0.00034499168396 0.000468015670776 - 0.000813007354736 PHP faster by :0.000280857086182 0.000524997711182 - 0.000805854797363 PHP faster by :0.000319004058838 0.000500917434692 - 0.00081992149353 PHP faster by :0.000659942626953 0.00047492980957 - 0.00113487243652 QRY faster by :0.000424146652222 0.0012640953064 - 0.000839948654175 PHP faster by :0.000411987304688 0.000391960144043 - 0.00080394744873 PHP faster by :0.000409841537476 0.000393152236938 - 0.000802993774414 PHP faster by :0.00040078163147 0.000395059585571 - 0.000795841217041 PHP faster by :0.000392913818359 0.000403165817261 - 0.00079607963562 PHP faster by :0.000401020050049 0.000396013259888 - 0.000797033309937 PHP faster by :0.000380992889404 0.000416994094849 - 0.000797986984253 PHP faster by :0.000495910644531 0.000389099121094 - 0.000885009765625 PHP faster by :0.000411987304688 0.000391960144043 - 0.00080394744873 PHP faster by :0.000400066375732 0.000405073165894 - 0.000805139541626 PHP faster by :0.000410079956055 0.000391960144043 - 0.000802040100098 PHP faster by :0.000412940979004 0.000388145446777 - 0.000801086425781 PHP faster by :0.000998973846436 0.000396013259888 - 0.00139498710632 PHP faster by :0.000407934188843 0.000395059585571 - 0.000802993774414 QRY faster by :0.000292062759399 0.00124311447144 - 0.000951051712036 PHP faster by :0.000439167022705 0.000391960144043 - 0.000831127166748 PHP faster by :0.000866889953613 0.000389099121094 - 0.00125598907471 PHP faster by :0.000408887863159 0.000400066375732 - 0.000808954238892 PHP faster by :0.000417232513428 0.000392913818359 - 0.000810146331787 PHP faster by :0.000415086746216 0.000393867492676 - 0.000808954238892 PHP faster by :0.000421047210693 0.000391006469727 - 0.00081205368042 PHP faster by :0.00041389465332 0.000395059585571 - 0.000808954238892 PHP faster by :0.000414848327637 0.000389099121094 - 0.00080394744873 PHP faster by :0.000419855117798 0.000393152236938 - 0.000813007354736 PHP faster by :0.000417232513428 0.000512838363647 - 0.000930070877075 PHP faster by :0.000409126281738 0.000388860702515 - 0.000797986984253 PHP faster by :0.000411987304688 0.000388860702515 - 0.000800848007202 PHP faster by :0.00041127204895 0.00038480758667 - 0.00079607963562 PHP faster by :0.000415802001953 0.000388145446777 - 0.00080394744873 PHP faster by :0.000412940979004 0.000389099121094 - 0.000802040100098 PHP faster by :0.000412940979004 0.00039005279541 - 0.000802993774414 PHP faster by :0.000915050506592 0.000385046005249 - 0.00130009651184 PHP faster by :0.000320911407471 0.000483989715576 - 0.000804901123047 PHP faster by :0.000415086746216 0.000391006469727 - 0.000806093215942 PHP faster by :0.000419855117798 0.000396013259888 - 0.000815868377686 PHP faster by :0.000414848327637 0.000388145446777 - 0.000802993774414 PHP faster by :0.000408172607422 0.000391960144043 - 0.000800132751465 PHP faster by :0.000945091247559 0.000388860702515 - 0.00133395195007 PHP faster by :0.000409841537476 0.000394105911255 - 0.00080394744873 PHP faster by :0.000416994094849 0.000391006469727 - 0.000808000564575 PHP faster by :0.000655651092529 0.000393152236938 - 0.00104880332947 PHP faster by :0.000524044036865 0.000395059585571 - 0.000919103622437 PHP faster by :0.000411987304688 0.000385999679565 - 0.000797986984253 PHP faster by :0.000810861587524 0.000389099121094 - 0.00119996070862 PHP faster by :0.000418901443481 0.000391006469727 - 0.000809907913208 PHP faster by :0.000416994094849 0.000389099121094 - 0.000806093215942 PHP faster by :0.000427961349487 0.000399112701416 - 0.000827074050903 PHP faster by :0.000445127487183 0.000395059585571 - 0.000840187072754 PHP faster by :0.000355958938599 0.000424146652222 - 0.00078010559082 PHP faster by :0.00093412399292 0.000375986099243 - 0.00131011009216 PHP faster by :0.000789880752563 0.000403165817261 - 0.00119304656982 PHP faster by :0.000420093536377 0.000396966934204 - 0.000817060470581 PHP faster by :0.000411033630371 0.000391006469727 - 0.000802040100098 PHP faster by :0.000423908233643 0.000386953353882 - 0.000810861587524 PHP faster by :0.000442028045654 0.000391960144043 - 0.000833988189697 PHP faster by :0.00114011764526 0.000401973724365 - 0.00154209136963 PHP faster by :0.000420808792114 0.000392198562622 - 0.000813007354736 PHP faster by :0.000306129455566 0.000504970550537 - 0.000811100006104 PHP faster by :0.000336885452271 0.000473022460938 - 0.000809907913208 PHP faster by :0.000412940979004 0.0003981590271 - 0.000811100006104 PHP faster by :0.000419139862061 0.000386953353882 - 0.000806093215942 PHP faster by :0.000409126281738 0.000396013259888 - 0.000805139541626 PHP faster by :0.000429153442383 0.000391960144043 - 0.000821113586426 PHP faster by :0.00040602684021 0.000393867492676 - 0.000799894332886 PHP faster by :0.00041127204895 0.000387907028198 - 0.000799179077148 PHP faster by :0.00040602684021 0.000396013259888 - 0.000802040100098 PHP faster by :0.000472068786621 0.00048303604126 - 0.000955104827881 PHP faster by :0.000577926635742 0.000468969345093 - 0.00104689598083 PHP faster by :0.00032901763916 0.000484943389893 - 0.000813961029053 PHP faster by :0.000324726104736 0.000477075576782 - 0.000801801681519 PHP faster by :0.000331878662109 0.000469923019409 - 0.000801801681519 PHP faster by :0.000359058380127 0.000468969345093 - 0.00082802772522 PHP faster by :0.000334024429321 0.00046706199646 - 0.000801086425781 PHP faster by :0.000325202941895 0.00047492980957 - 0.000800132751465 PHP faster by :0.000371217727661 0.000470876693726 - 0.000842094421387 PHP faster by :4.29153442383E-05 0.000797033309937 - 0.000839948654175 PHP faster by :0.000309944152832 0.000498056411743 - 0.000808000564575 PHP faster by :0.000505208969116 0.000476837158203 - 0.000982046127319 PHP faster by :0.00117111206055 0.00120401382446 - 0.00237512588501 PHP faster by :0.000298976898193 0.000488996505737 - 0.000787973403931 PHP faster by :0.000324010848999 0.000458955764771 - 0.00078296661377 PHP faster by :0.000342130661011 0.000458955764771 - 0.000801086425781 PHP faster by :0.000323057174683 0.000463008880615 - 0.000786066055298 PHP faster by :0.000323057174683 0.000460863113403 - 0.000783920288086 PHP faster by :0.000317096710205 0.000464916229248 - 0.000782012939453 PHP faster by :0.000832796096802 0.00045919418335 - 0.00129199028015 QRY faster by :0.000553131103516 0.00143814086914 - 0.000885009765625 QRY faster by :5.79357147217E-05 0.00163888931274 - 0.00158095359802 PHP faster by :0.000288009643555 0.000504016876221 - 0.000792026519775 PHP faster by :0.00089168548584 0.00045919418335 - 0.00135087966919 PHP faster by :0.000316143035889 0.000465869903564 - 0.000782012939453 PHP faster by :0.000323057174683 0.000464916229248 - 0.000787973403931 PHP faster by :0.00107789039612 0.00274300575256 - 0.00382089614868 PHP faster by :0.0012469291687 0.00280690193176 - 0.00405383110046
  10. i was wondering how to document your functions like that with PHP. Thanks
  11. well i tried to do it again, but under very intense testing... looping each method 10000 times, while keeping a average time and a count on which was faster... Needless to say, I froze my VPS and it has been off-line for the past 6 hours HAHA!~ It's safe to assume then, that it is less intensive and quicker to go with one db query and split the data as needed into the arrays instead of two queries.
  12. Read this -> http://www.sitepoint.com/forums/showpost.php?p=498687&postcount=15 What do you guys think? I think he's right, a template engine just makes things go that much slower...
  13. the database returns ~1000 results each query. The connect to the database was made once, then queries ran each time, then the database was closed in the end. The objective is to get two arrays, to be passed into a template engine for display into two tables, one for each kind of data. my DB abstraction layer, so you can see it ;p, though please explain what it has to do with it? <?php class MySQL{ protected $con; protected $res; protected $query; protected $connected; protected $server; protected $user; protected $pass; protected $database; function MySQL($server, $user, $pass, $database){ $this->server = $server; $this->user = $user; $this->pass = $pass; $this->database = $database; $this->query = ""; $this->connect(); } function selectDB($db){ mysql_select_db($db, $this->con); } function connect(){ $this->con = mysql_pconnect($this->server, $this->user, $this->pass) or trigger_error(mysql_error(), E_USER_ERROR); $this->selectDB($this->database); $this->connected = true; } function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); } function queryGetResults($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); return new results($this->res); } function queryError(){ echo "Unable to process query<br />"; $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $this->query; die($message); } function getResults(){ return new results($this->res); } function fetch(){ return mysql_fetch_row($this->res); } function close(){ if(!$this->connected) return; mysql_close($this->con); $this->connected = false; } } class results{ protected $data; function results($res){ $this->data = $res; } function getResults(){ return $this->data; } function free(){ mysql_free_result($this->data); } function fetch(){ return mysql_fetch_assoc($this->data); } function fetchTable(){ $table = array(); if(mysql_num_rows($this->data) == 0) return $table; mysql_data_seek($this->data, 0); while($row = mysql_fetch_array($this->data, MYSQL_BOTH)){ array_push($table, $row); } return $table; } function fetchTableAndFree(){ $table = $this->fetchTable(); $this->free(); return $table; } } ?>
×
×
  • 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.