Jump to content

berridgeab

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by berridgeab

  1. Testing locally requires a mailserver setting up which is out of the scope of this post, though there are examples online. I find it a pain to setup correctly so instead I test emails on my live production server. I can't see any problems with the above code so it should work ok.
  2. When you echo $contents, what is the actual output?
  3. Make sure you have called session_start() first. Make sure the folder pemissions where session text files are saved are setup correctly so that PHP can write, edit, and delete files.
  4. I went with fully qualified in the end. Took a day but I got the job done . At the start of the project I opted not to use a starting class name like Project_* to save typing. If I had Netbeans could of done a search and replace in 10 seconds , Oh well.
  5. Hi Yes Ive been testing locally and reading further and stumbled upon this article. That article highlights all the pitfalls you will encounter with PHP namespaces which I just learnt myself. After the require_once / include_once debacle (before autoloading) you would have thought they would have at least supported some kind of command to put entire namespaces into the global namespace or be able to wildcard a namespace to make it easier. Unfortuantely I have come across a part of my project which will require namespaces so I now have to make the decision of Using fully qualifed class names throughout my code. Creating a 'use' list at the top of every included file. I will probably go with fully qualifed space names. Netbeans autocomplete makes this ideal and it saves having to maintain a 'use' list (which resembles a list of require_onces I used to see in my code) at the top of every included file. Thanks for your input.
  6. Hi I have just recently tried to incorporate namespaces into my framework but having trouble understanding how I should use them in my project. I have a class called Foo which is part of the namespace \CompanyName\Project. namespace \CompanyName\Project; class Foo { } I have a file called index.php. index.php needs to use that class. index.php handles the autoloading of that class (ive omitted the autoloading code). My index.php looks like below. $foo = new Foo(); This code fails because it can't find class Foo. I can make it work by using the fully qualified name instead. $foo = new \CompanyName\Project\Foo(); I can also make it work by making index.php part of \Company\Project\ namespace. namespace \CompanyName\Project; $foo = new Foo(); Basically my problem is that I have lots of different file includes for individual pages on my site. They all use the old unqualifed class names which are not getting resolved by PHP because it can no longer find them as all of the classes now belong to a namespace. Do I A - Go through every included file and change every class name to the fully qualifed class name? B - Go through every included file and make every file part of the \CompanyName\Project namespace (This feels like the wrong solution)? C - Make PHP treat the old unqualifed class name as a global through use of the 'use' statement. I don't know how to do this. The trouble is there could be 10 - 20 different classes per file which would mean 20 different use declarations. Ideally it would be great if I could import an entire namespace into the global namespace like "use \CompanyName\Project as \;". Basically I want a way to move all classes and functions from a particular namespace into the global namespace so I can use the unqualifed class names throughout the included files. And I want to be able to do it from one file, index.php. I don't think this is possible though as PHP does state I think it will have to be option A , before I begin, am I on the right track?
  7. Hi yes your right I just read somewhere else. $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); I was setting to true not false, changing to false resolved the memory problem. Thanks again.
  8. Hello I use PDO to communicate with MySQL. I am trying to get a rowcount of a 600, 000 row table from MySQL using the code below. $pdo = new PDO("mysql:host=127.0.0.1:3306;dbname=$databaseName", $password, $username, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); $pdoStatement = $pdo->prepare("SELECT count(*) FROM LargeTable"); $pdoStatement->execute(); echo $pdoStatement->rowCount(); When I run the code I get the following error. My PHP ini setting for memory limit is 256mb. I don't actually need all 600,000 rows but the only way I can get the total number of rows is by doing a SELECT COUNT. Is there any way of getting this figure with PDO without actually hitting the memory limit. I know the easy answer is to increase the php memory limit, but what happens in 2 years time when my table reaches 20 million rows and by theoretical 1.5gb memory limit doesn't cut it anymore?
  9. Your $img has been passed html encoded values. If you decode your name you will have the correct name which should be Staff map (b&w) by AVERY EASTER<br/>Canon plant<br/>. getJpeg(html_entity_decode($img));
  10. Ive gone against the rewrite. Ive decided to let MySQL take the performance hit instead and load the classes on each page rather than putting them in a session.
  11. Yes I can do, but that could be any one of 25 - 50 classes and my session_start() happens quite early on. The only solution I can see is to have some way of loading my required classes before the session_start() is called but thats quite a big project rewrite. Thanks anyway.
  12. Hello I am struggling to store a simple PHP class within a PHP session. When I try to access the class stored in my session I get the following "Fatal error: main(): The script tried to execute a method or access a property of an incomplete object." Google tells me this is because I haven't included my class definition before calling session_start(). The solution would be to require_once() every PHP class my site uses before calling session_start(). Only thing is there are about 100 classes. Would this not add a ton of overhead to every PHP page that loads (Because it is loading 90+ unneeded classes) or is this common practice? Currently I only require_once() the classes I need on a per page basis so I reduce overhead. But most of these require_once() calls come after I have called session_start().
  13. Thanks for the clarification.
  14. Hi Just fishing for opinions here, is it a good idea to break classes down to skeleton parts? i.e. I have a class called Person. class Person { public $id; public $name; public $age; //Getters / Setters Go here function id() { return $this->id; } function load($id) { //Database loading logic here } } To something more reuseable i.e. abrstract class SkeletonPerson { public $id; public $name; public $age; //Getters / Setters Go here function id() { return $this->id; } } class Person extends SkeletonPerson { function load($id) { //Database loading logic here } }
  15. Bonjour! I have come across some strange behaviour in MySQL when performing a simple select. InnoDB Table table1 has one column called Qty. Qty is an datatype INT unsigned column. Therefore the only acceptable values for this column are numeric values and NULL. The query I am performing is So when I perform the query, I would naturally expect MySQL to return 0 results as the column cannot possibly contain any data that matches "2Apples" due to the alphanumeric searchstring. But it does return results, specifically any value matching "2". It is like MySQL is automatically rewriting the my query to match the following Does MySQL automatically omit non-numeric characters on a searchstring targeting a column with an INT type? Is it performing some kind of casting on the searchstring due to the column datatype being INT? I notice if I change the query slightly so that the text begins the searchstring, this behaviour disappears and I get 0 results, as intended. Its not really a problem, just a peculiarity and wanted someone to explain to me why it does this. I have scoured the MySQL documentation but could not find anything related to this.
  16. No worries, it appears the browser converts the entities back to there valid characters at some point.
  17. Hello Im quite confused at what filtering I should use on my data when pulling it from a MySQL database. I don't sanitize my data on input because I am using prepared statements with PHP's PDO Driver which means I don't need to use mysql_real_escape_string() at all. When I pull the data to be displayed i.e. in a HTML Table I use the below function to make it safe for HTML output. public static function htmlSafe($data) { return nl2br(htmlentities($data, ENT_QUOTES)); } However the rules change when Im using a HTML Form to edit the data, and I am unsure what I need to strip out. I.e. What would I need to do to make all data safe to insert into the following form input. <input id = "someInput" type = "text" value = "<?php echo $someVarThatNeedsFiltering ?>" /> Also, one more question, in my html attributes (Valid ones like class, name, id, style, _target) I use a mixture of double quotes(") and single quotes ('), for quoting my values. Which one should I use or which one is more valid, doubles, or singles?
  18. Scrap the above, further testing shows it doesn't work on 10.00, 20.00, 30.00, 1.00, etc. Back to the drawing board....
  19. As this is the 3rd result in the google search results, I thought I'd post the answer I found lurking on some other website. To validate a True Decimal Number. //if the number is not a whole number then its a decimal. function validateTrueDecimal($v) { return(floor($v) != $v); } //A Small Unit Test $test = array (0.5, 0.12, 0.56, 1, 10, "Apples", -13.4, -5.12178934123487123491912471249124, 1e7, "1e7", "1.2"); foreach($test as $value) { if (validateTrueDecimal($value)==true) { echo $value . " - Number is a decimal<br>";} else {echo $value . " - <b>Number is not a decimal</b><br>";} } Output of Code -
  20. Ah yes, I should have read his comments, my bad been a long day
  21. Sorry to bump a post from two years ago but when I googled my question this was one of the first links that came up and it didnt solve my answer. This may prove useful to anyone trying to evaluate a whole number. For example I needed to check the quantity a customer was entering within a shopping cart. If it wasn't a true whole number I needed to output an error. Casting (int) doesn't help becuase Hexadecimal values still gets evaluated to its true integer value. ////////////////////////////////////////////////////////////////////////////////////////////// //is_wholeNumber(string $value) //Returns TRUE if a WHOLE NUMBER //Returns FALSE if anything else (Float, String, Hex, etc) ////////////////////////////////////////////////////////////////////////////////////////////// function is_wholeNumber($value) { if(preg_match ("/[^0-9]/", $value)) { return FALSE; } return TRUE; } *EDIT* opps, sorry, forgot credit to original author http://davidwalsh.name/php-validatie-numeric-digits
  22. Further to this Ive just got my desired resultset by adding a 'CatagoryID' field to my post Table. I didn't want the extra field there but it seems to be the only way to resolve my problem in one query. Never know, might aid me in the long run.
  23. Yeah, I only used the Hope.* to save me a bit of typing to otuput all fields from that table. But even when I specifically selecr the columns I need from table Hope it still gives the same result set, so thats not the problem. I really need to move on with this so for now Ive opted to use - SELECT c.CatagoryID AS 'Catagory ID', c.CatagoryTitle AS 'Catagory Title', c.CatagorySubject AS 'Catagory Subject', COUNT(DISTINCT mCount.MessageID) AS 'Total Messages', COUNT(DISTINCT pCount.PostID) AS 'Total Posts', Hope.PostID AS 'Hope.Post ID', Hope.MessageID AS 'Hope.Message ID', p.PostID AS 'p.Post ID', p.MessageID AS 'p.Message ID', Hope.PostTime, Hope.Post FROM onecall.sv2_department_members dm, onecall.sv2_department_rules dr, onecall.sv2_message_catagory c, onecall.sv2_message_message mCount, onecall.sv2_message_post pCount JOIN ( SELECT p.PostID, m.MessageID, m.CatagoryID, p.PostTime, p.Post FROM onecall.sv2_message_post p, onecall.sv2_message_message m WHERE m.MessageID = p.MessageID ) AS Hope LEFT OUTER JOIN onecall.sv2_message_post p ON (p.PostID > Hope.PostID) WHERE dm.UserID = '168' AND dr.DepartmentID = dm.DepartmentID AND c.CatagoryID = dr.CatagoryID AND mCount.CatagoryID = c.CatagoryID AND pCount.MessageID = mCount.MessageID AND Hope.CatagoryID = c.CatagoryID GROUP BY Hope.CatagoryID, Hope.PostID ORDER BY Hope.CatagoryID, Hope.PostID ASC From the resultset generated I can use PHP to do the rest of the filtering. Feels very hacky considering all I wanted is the last row of each Hope.CatagoryID, will come back to it at a later date when I have more time to spend on it. From what I have read online, all other major databases have a very 'easy' function to do what I require, only MySQL seems to be the outsider on this one. Thanks for your reply anyway.
×
×
  • 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.