Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Just like this: require_once('config.php'); $db = new MySQL($config['host'], ..); $r = $db->execute('SELECT * FROM table'); Of course you really shouldn't do this if you want your application to be able to use multiple DBMS systems (like MySQL and MSSQL) It would therefor be better to use a Factory pattern or Builder pattern, like: require_once('config.php'); $db = DatabaseConnect::factory($config['db1']['scheme']);//mysql://ignace:password@localhost:3610/database $query = new DatabaseQueryBuilder(); $insert = $query->insert($data)->into('table'); You don't have to worry just yet about the above code. Yup, to make sure every class does just one thing and one thing only. This makes that the class has a high-cohesion (other name for little number of methods) and adheres to the separation of concerns (the class minds his own business and is only told on a need-to-know basis) How do you mean? mssql_* of course? Or do you mean the methods it would possess? All those defined in the Database interface of course.
  2. At best you will get a value that has a collision and therefor generates the same hash, but it should be noted that this is/was not the actual value.
  3. Would this work? SELECT left(field,1) AS letter, count(*) AS letter_count FROM table GROUP BY letter ORDER BY letter ASC
  4. Indeed. And in most cases (if you were to develop this for a real client) your client would want to run analytics on your software like how many people purchase extra slots? So that he can see the needs of his market and he knows where to invest his money next when he wants to expand your software. This would mean you would need to keep track of these purchases for each customer of your client. Also don't tie yourself to my database design most presumably it won't fit the bill.
  5. Your boss wants you to create a website that hosts illegal content? Maybe you should remind your boss of the applied fees when caught with illegal software.
  6. ignace

    Education

    OMG you lucky bastard. I'm migrating to Denmark as of now!! And high tax systems, I'm living in Belgium how much higher can it get? Our government just dug a whole that took us years to fill and now we are back where we started at 130% of the BBP (in english: Bruto Domestic Product?).
  7. See my sig, it's really great. It for example supports Zen Coding, a little example: html5>head+body>div#wrapper>div#header+div#content+div#footer creates <!DOCTYPE html> <html> <head> </head> <body> <div id="wrapper"> <div id="header"></div> <div id="content"></div> <div id="footer"></div> </div> </body> </html>
  8. What you gave as an example is indeed correct although I would add the access modifier for all methods, like interface Database { public function __construct($server, $username, $password, $database); public function connect(); public function connect_db(); public function select_db(); public function execute($query); } From this point you can move towards a more SRP (Single-Responsibility Principle) friendly design? DatabaseQuery DatabaseResult DatabaseConnect DatabaseQueryBuilder Learn more about this in the Doctrine 2.0 API and take a peek in Zend framework 1.10 API for more information about design patterns and (H)MVC architecture.
  9. Sure, just store it in a cookie through JS.
  10. I like it, although the text needs some more spacing and maybe a different color?
  11. QFT Really Mchl, do you talk like this in real life? All those abbreviations, what does QFT mean?
  12. It wouldn't make a decision it just used that line to verify that it's either of those classes and not SomeObject. MsSQL and MySQL share both the same functions (with a varying implementation mysql_* vs mssql_*). Not the interface but the implementing class. interface Database { public function execute($query); } class MySQL implements Database { private $connection; public function execute($query) { return mysql_query($query, $this->connection); } } Your interface is actually your "validator" (if ($m instanceof MySQL || ..) public function someFunction(Database $d) { return $d->execute('SELECT * FROM table'); } I could use this function like this: $o->someFunction(new MySQL()); $o->someFunction(new MsSQL()); $o->someFunction(new Oracle()); And it would all work as I know each of these (MySQL, MsSQL, Oracle) implement a execute() method as the interface Database said they should, and if they didn't an exception is thrown. I couldn't for example do: $o->someFunction(new SomeObject()); As SomeObject does not implement the Database interface and may therefor not have an execute() method (or has a different order of it's parameters) which I need in the someFunction() method.
  13. I am indeed a Flemish person Yeah Brussels indeed has a lot of graffiti. All are written in French by rival graffiti gangs. Besides football team supporters that hate one another we also have the Flemish VS Walloons as the latter refuses to speak Flemish even in the Flemish parts and demand that we (Flemish) speak French or now that we no longer have a government they demand that we give even more of Belgium to the Walloons if we want to split BHV. We have an old grudge against French (since WW2 and the "Et pour le Flamand, le meme choice"-incident) as we are proud of our language. Even our King barely speaks Flemish. To bad we have such a great health care and education (that is also they only things we are great at though) or I would have bolted a long time ago. http://www.askmen.com/specials/top_29_cities/ -- is a good start if I ever would decide to move
  14. I do to I live in Landen, Vlaams-Brabant about 30 min from Brussel Bruxelles is how they name it in Brussel due to the many french living there. [dutch]Spreek je ook nog Nederlands of Vlaams in de volksmond?[/dutch]
  15. Start > Computer > right mouse click > Add Nework Location > Follow Instructions Or try http://support.microsoft.com/kb/308416
  16. You have comments for that. It's probably just me who thinks every bit of CPU-time should be used optimally, even if we are talking about a few nano-seconds here.
  17. Java != JavaScript. I don't see why they would show the keyboard for Europe countries only?
  18. I think it would be best to keep the links table and add a boolean field called user_contributed
  19. Thank you roopurt and aeroswat for clearing this up for me.
  20. <? should be <?php ALWAYS //error_reporting(~E_NOTICE); should be error_reporting(E_ALL); ALWAYS $customerid=mysql_insert_id(); only works after you actually inserted something mysql_query("insert into customers values($customerid,$name,$email,$address,$phone)"); this query fails everytime use ' to surround the values mysql_query("insert into orders values($orderid,$date,$customerid)"); same as before $date=date('YY-mm-dd'); seriously consult the manual on date <?=get_order_total()?> should be <?php echo get_order_total(); ?> validate both client and server-side as the client can disable JS
  21. I'll provide an example to explain interface's, take your class Database for example it utilizes mysql_* functions imagine now that your client uses mssql so you could re-write it or you could extend it, like: class DatabaseMsSQL extends Database {} Which would be dumb because if you now forget to implement one method using mssql your application would fall back to mysql leading to serious errors, so you re-wrote it. You now have 2 classes both named Database but a varying implementation and you can't call them both, the below for example will fail: require('mysql/database.php'); require('mssql/database.php'); Now a new client comes along which has - you guessed it - 2 database servers one in mysql and one in mssql both used for their specific features (to keep it optimized). This is just a fictive example of course but it is possible. Anyway so you rename both classes you name one MySQL and the other MsSQL and you can include both. The client is pleased with your work and now want some new functionality added one that will require you to pass the $db object (either MsSQL or MySQL) to a method that will act upon it's result and return some stuff. This doesn't work: public function someFunction(MySQL $m) {} public function someFunction(MsSQL $m) {} You could do of course (as PHP does not require a type to be specified): public function someFunction($m) {} But how will you know it will be a MsSQL or MySQL object? if ($m instanceof MySQL || $m instanceof MsSQL) But what if the user also adds a Oracle database? if ($m instanceof MySQL || $m instanceof MsSQL || $m instanceof Oracle) And what if multiple methods require a database object? You can't possibly write all that code and modify it every time a new database is introduced??? So, we create an interface like: interface Database { public function query($sql); .. } Our method will hold: public function someFunction(Database $d) {} And our classes MySQL, MsSQL, and Oracle will implement this interface: class MySQL implements Database Now we can pass any class that implements Database to someFunction() without having to worry it wouldn't have a query() method. I hope this explained it well, I have tried to keep it as simple as possible using various (im)possible scenario's
  22. If you click the little keyboard icon you get that big keyboard on screen.
  23. I have edited your PHP code and marked it, all you need to do now is add before or after the <form> tag: <?php if (isset($_GET['message'])): ?> <p class="error"><?php print $_GET['message']; ?></p> <?php endif; ?> The edited code if (isset($_POST['submit'])) { $db = mysql_connect('localhost', 'onina', 'example') or die("Couldn't connect to the database<br>" . mysql_error()); mysql_select_db('oninacom_concierge', $db) or die("Couldn't select<br>" . mysql_error()); $login = mysql_real_escape_string($_POST['login'], $db); $password = mysql_real_escape_string($_POST['password'], $db); $query = "SELECT privilage FROM auth WHERE login = '$login' AND password = '$password'"; $result = mysql_query($query, $db) or die("Problem with the query: $query<br>" . mysql_error()); if (0 === mysql_num_rows($result)) { //EDITED CODE HERE header('Location: ../../index.php?message=' . urlencode('Incorrect username and/or password')); //EDITED CODE HERE exit(0); } $row = mysql_fetch_assoc($result); $privilage = $row['privilage']; session_start(); $_SESSION['username'] = $login; $_SESSION['privilage'] = $privilage; if ('receptionist' === $privilage) { header('Location: ../../employees/receptionist/index2.htm'); exit(0); } if ('manager' === $privilage) { header('Location: ../../employees/managers/index1.htm'); exit(0); } if ('administrator' === $privilage) { header('Location: ../../admin/index.php'); exit(0); } } Add to the pages you want to protect: if (empty($_SESSION['login']) || empty($_SESSION['privilage'])) { header('Location: ../../index.php');//this path may be incorrect, please correct exit(0); } Create a file with the .css extension and link to it using the <link> tag as: <link href="style.css" type="text/css" rel="stylesheet" media="screen"> Make that a common .php file so no-one can read it and include it: require 'db.php'; You can use the same setup for the rest of the website You can create one using JS, just take a look at google.com click the little keyboard in the search bar.
  24. No need to say sorry this forum's primary goal is for you, me and many others to ask questions. No just use the maximum_uploads and the number of uploads the user has already made in a conditional statement and deny the upload if they exceed it. After giving this some more thought I came up with: plan_status (id, name) -- Silver, Bronze, Gold plan_license (id, length_in_months) -- 3, 6, 12, .. plan (id, status_id, license_id, maximum_uploads, pricing) member_plan (id, member_id, plan_id, date_purchased) In the future you may want to expand to to 24 or more months, you also may want to change the maximum uploads & price according to the status & license. You also may want to keep track of all plans a user has bought to come up with the most popular plan. I don't have the full background as your client may have in what he wants and at best I can guess, it's up to you to ask questions to your client to gain a full understanding of what he wishes to achieve and modify your design accordingly.
×
×
  • 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.