Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. If projectId is an AUTO_INCREMENT NOT NULL PRIMARY KEY value then you can leave set it to NULL or DEFAULT $query = " INSERT INTO project (projectId, x1, x2, x3, companyId) VALUES (NULL, '$exone','$extwo','$exthree','$id')"; or $query = " INSERT INTO project (projectId, x1, x2, x3, companyId) VALUES (DEFAULT, '$exone','$extwo','$exthree','$id')";
  2. SELECT concat(Name,' is from ',upper(Location),'. The ASCII character of the number ',Number,' is ',ascii(Number)) FROM people Your teacher can also browse the web, just so you know
  3. 1) SQL is a bad name for a DB class, as DB is much broader then SQL. I could use a webservice as a database, or an XML file, or CSV, or .. 2) Keep in mind that more and more projects require to be able to connect to multiple databases, whether that being a SQL database or just flat-file. 3) Don't use die(), exit() or anything like that in your classes, learn Exception's and use them well 4) Don't tie business logic (returnAmount) to your DB, but to your Model's (User, Product, ..) 5) Don't use define() inside your classes, but use const instead. Use variables for dynamic values instead of resorting to store it in constants. 6) Validation is very broad and not reusable in any other projects. OO is about reusability, think of this while designing your objects.
  4. get() in this scenario is a Factory method. Instead of writing new Justin() which would be weird, I can't spawn you. You were born, not spawned at a set age. So instead I retrieve you, like "Hey Justin, got a minute?" (except your reply is always: "Yeah, sure!") Besides being less weird, it also makes your software flexible as it removes the hard dependency between Justin and your Object. Meaning you will only have to change the People class to return a different object when they call Justin instead of having to replace any and all occurences with the new class throughout your project. It was a joke
  5. Like: $this->Join('Orders', 'Users.Firstname = Orders.Firstname'); An ActiveRecord class is not a Query Object (or Interpreter). The Active Record defines behavior specific to a record. class User { public function verify($verificationCode) { /* after successfull validation, activates the user account */ } }
  6. $character_one_status + 1 should be: $character_one_status += 1 This will solve your problem, but you are still far from writing true OOP. Every Object has methods, or behavior like we call them. In real-world we could define behavior as an action someone/something undertakes, like attacking. interface Character { public function attacks(Character $c); } Here, I have defined that any Character can attack any Character (even itself: self-mutilation, suicide, ..). And a method to make the Character actually take damage: interface Character { public function attacks(Character $c); public function takeDamage($d); } To give your Character more of a real-world feel you could change attacks to punches. interface Character { public function punches(Character $c); public function takeDamage($d); } The actual implementation of punches may look something similar to: class Justin implements Character { public function punches(Character $c) { $c->takeDamage($this->_calculatePunchDamage()); } } $justin = People::get('Justin'); $justin->punches(People::get('Bieber'));
  7. @kartul It worked for you because you are using MyISAM @baldiajaib companyId will only be auto-generated when you insert something in company table not in project table. In your project table you MUST give a companyId as it's a foreign key and you specified he column as NOT NULL. Inserting a record into project table without a companyId specified will lead to give that column a value of NULL, which by NOT NULL means 0 and 0 is not a PK in your company table. So either specify the column as nullable (not recommended) OR make sure you always specify a value for companyId in your projects table (recommended)
  8. Only when you call it directly and even that's only to tell Apache it should pass it to the PHP extension. Include will read the file and parse any containing PHP code, the extension in this case does not matter. include('me.gif'); Would work aswell.
  9. Stats don't matter when you are airborne, the odds are always in your favor!
  10. Protected is only accessible to the class itself and it's siblings.
  11. Splitting up HTML and PHP doesn't mean you can't show any error's, you can just pass them: $errors = array(); include('page.html'); In your page.html you could then have: <?php if(sizeof($errors)): ?> <ul> <li><?php print $errors[0]; ?></li> </ul> <?php endif; ?> Show us your entire script and I'll show you how you can refactor it for reusability.
  12. INSERT INTO project(x1,x2,x3, companyId) VALUES ('$exone','$extwo','$exthree', ??) You need to pass the companyId as your foreign key enforces that the inserted value exists in the company table, and NULL does not.
  13. It should be: CREATE PROCEDURE customer_proc3 (IN cus_id INT(11), IN lname VARCHAR(50), IN fname VARCHAR(50), IN dobirth date, IN phone_num VARCHAR(20), IN the_result INT) OUT is if you want to pass a variable (by-reference, not a constant thus like 5 or '2011-04-09') and the changes to be made visible to the caller, the initial value is NULL within the procedure unlike INOUT where the caller can set a value prior to passing it to the callee.
  14. Indeed. MyISAM even returns it straight away without actually having to go over the entire table.
  15. $offset = ($_GET['page'] - 1) * $p_page; Add this check: if(!isset($_GET['page']) || $_GET['page'] < 1) $_GET['page'] = 1; PS to reverse engineer use: $page = $offset / $p_page + 1;
  16. Sure, but even then you still can use proxy server's or use shared hosted servers (at least if the data you fetch brings in lots of money) across the world or .. PS I am not trying to be smart here, I hate this just as much as you do. As we are not only crawling websites every day, we also have to protect against it. And sometimes make some arrangements/meetings to avoid a lawsuit
  17. Sure, just make sure you set: User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) To avoid being blocked, only very few actually check the IP-address
  18. Exactly. Thanks for apologizing, takes a lot Indeed.
  19. The AJAX-call will constanly ask the server if the field changed, if you have many users on your website it will have to answer a lot of "questions" slowing it down. Using push tells the user when something happened, like for example when the other user left to abort the game.
  20. Using a push-notification system like: http://www.ape-project.org/
  21. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=329534.0
  22. class MyUsersDao { public function findByLastName($lastName) {} } FindName is not a good name for a class, actions should be methods not objects.
  23. http://php.net/mysql-fetch-assoc
×
×
  • 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.