Jump to content

StevenOliver

Members
  • Content Count

    91
  • Joined

  • Last visited

  • Days Won

    1

StevenOliver last won the day on November 25 2018

StevenOliver had the most liked content!

Community Reputation

5 Neutral

About StevenOliver

  • Rank
    Regular Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. StevenOliver

    mySQL and rebuilding keys

    No -- no warnings. I created the tables with both "primary key col2 (col2)" and "primary key (col2)" and there were no warnings. Then I tried the "alter table" syntax after dropping the primary keys: "alter table Table1 add primary key col2 (col2)" -and- "alter table Table1 add primary key (col2)" ... and neither of those gave any warnings. For all intents and purposes, they seem 100% identical. Perhaps in the olden days the "...primary key col2 (col2)" was how it used to be done, then it got deprecated and now "...primary key (col2)" is how it's done today, with both commands having the same effect. What are your thoughts?
  2. StevenOliver

    mySQL and rebuilding keys

    show index from Table1; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table1 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec) show index from Table2; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table2 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec)
  3. StevenOliver

    mySQL and rebuilding keys

    I did -- I did "show index from Table1" and the result was identical to "show index from Table2."
  4. StevenOliver

    mySQL and rebuilding keys

    Hmm... I did that, the results are absolutely identical. I created the tables like this: Create table Table1( col1 varchar(3), col2 varchar(3), primary key col2 (col2) ); Create table Table2( col1 varchar(3), col2 varchar(3), primary key (col2) ); What would you think I should be seeing that I'm missing?
  5. StevenOliver

    mySQL and rebuilding keys

    Requinix, thank you!! That is exactly what I was looking for. (It actually talks about exactly what I'm asking -- what happens when you delete values, etc.). Thank you!! Regarding question 2... (good idea, by the way.... try both then describe the tables!).... So.... I just now created two tables, one with "...primary key (col3)" and the other with "...primary key col3 (col3)" but they both look the same, so I am still not quite sure what the difference is: describe Table1 +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | col1 | varchar(43) | YES | | NULL | | | col2 | varchar(3) | NO | PRI | NULL | | | col3 | varchar(3) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ describe Table2 +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | col1 | varchar(43) | YES | | NULL | | | col2 | varchar(3) | NO | PRI | NULL | | | col3 | varchar(3) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ I also ran the command "show index from Table1" and it was identical to Table2's index. Thank you.
  6. StevenOliver

    mySQL and rebuilding keys

    Requinix, thank you for your answers. Would you please clarify the "mySQL updates the index automatically" part? Given a database with 100000+ records: 1.) with Primary Key, takes .001 seconds to do a lookup. 2.) without Primary Key, takes 20 seconds to do a lookup. 3.) after removing primary key, "Add primary key" takes about 1 minute. If I alter a record, I can immediately do another lookup and it will only take .001 seconds. That must mean mySQL doesn't re-index the entire table when updating the index (because reindexing takes an entire minute, and if my table isn't reindexed yet, the lookup would take forever...). I wonder how and where it updates the index? Would you please clarify your "one key is named automatically" answer? What exactly is happening when I issue this command: ALTER TABLE mytable ADD PRIMARY KEY merchandise (merchandise) (I'm still not understanding the difference between "...add primary key columnName (columnName)" and "...add primary key (columnName)" Thank you!!
  7. StevenOliver

    mySQL and rebuilding keys

    Question 1.) When I change a record in a mySQL table with a key, how come I don't need to delete and recreate the entire key? I always assumed that a "key" is some sort of super-condensed index that probably gets loaded into mySQL memory. If that's the case, how come making changes to the records (even small changes) doesn't throw the entire key off? Question 2.) I've seen 2 ways of adding a primary key. Using an example column "merchandise," what are the differences and which way is better: a.) ALTER TABLE mytable ADD PRIMARY KEY (merchandise) b.) ALTER TABLE mytable ADD PRIMARY KEY merchandise (merchandise) Thank you!
  8. StevenOliver

    Arrays: concatenation operator .= vs =

    Thank you!! I saw an answer on the net using $array[] .= and I had never seen the concatenation operator used with arrays (the answer had lots of upvotes, too), so I thought I'd look into it further before changing my own code :-)
  9. Is there a subtle difference between $array[] = 'item'; vs $array[] .= 'item'; Thank you.
  10. StevenOliver

    Sessions Without Cookies in PHP 7

    I love this! This made my day!
  11. StevenOliver

    Sessions Without Cookies in PHP 7

    I'm trying to learn the proper workaround to enable Sessions when visitors have their cookies disabled. When I create a PHP session page with ini_set("session.use_trans_sid", 1) and then disable my browser cookies and view browser source code, I see what I expect: a hidden input appended like this: <input type="hidden" name="PHPSESSID" value="abc123456789reallylongstring1234" /> It seems to work (sessions without cookies!). However, I don't see the long URL query strings that I used to see when I experimented with this 10 years ago, and I don't see the long PHPSESSID value appended to all the page links, and I don't see dozens of session variables appended as hidden form inputs. Rather, I just see the one PHPSESSID hidden input described above. Is this because all the session variables are stored on the server itself, and all the server needs is that one single long PHPSESSID value? Or, am I doing it wrong? :-)
  12. StevenOliver

    Important "if" statement relying on mySQL

    Thank you!!
  13. StevenOliver

    Important "if" statement relying on mySQL

    Thank you! You just now reminded me of a question I've had since day one: On an if/else statement, if one condition is more likely to happen than the other, should that condition go first? Or, does it absolutely not matter. Using my example, it's extremely unlikely a visitor will try to print more than 5 labels (less than 1/100 chance). Would I want the first condition of the if/else statement to be the least likely scenario: if ($numberoflabels > 4) { echo 'sorry'; } else { // proceed everything fine } -or- Would I want the first condition to be the most likely scenario: if ($numberoflabels < 5) { // proceed everything fine } else { echo 'sorry'; } Does one version over the other operate faster?
  14. I have a "best practices" question. Visitors are limited to a maximum of 5 shipping labels per day, so mySQL counts how many were created in the past 24 hours and logs them. Which "style" is better? ### Style #1 ##################### $labelCounter = $db->prepare("SELECT count(*).. // mySQL counts labels if($numberoflabels < 5) { // RUN BIG CURL SCRIPT IF LESS THAN 5 LABELS // LONG CURL SCRIPT GOES HERE $log = $db->prepare("INSERT into label_counter... // log the good label } else { // don't run big curl script echo "Sorry visitor, no label could be created"; } ### Style #2 ##################### $too-many-labels = FALSE; $labelCounter = $db->prepare("SELECT count(*) // mySQL counts labels if($numberoflabels > 4) { $too-many-labels = TRUE; } if ($too-many-labels == FALSE) { // RUN BIG CURL SCRIPT IF LESS THAN 5 LABELS // LONG CURL SCRIPT GOES HERE } else { // don't run big curl script echo "Sorry visitor, no label could be created"; } Style # 1 seems more direct, but Style 2 somehow "looks safer." Which is really better? What are your thoughts, please?
  15. StevenOliver

    Assign Session Variables: Best Practices

    Thank you both! I like the "$trackingNumber = $_SESSION["trackingNumber"] = $result->parcelTrackingNumber;" line of code! I remember back in 1999 when server RAM was at a premium... assigning variables when not absolutely necessary was a no-no. And, when Sessions were invented, they made your page really, really slow. LOL
×

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.