Jump to content

vinny42

Members
  • Posts

    411
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by vinny42

  1.  


    you need to call mysqli::close() to release the memory it occupied once you are done with the query

     

    You're thinking of mysql_free_result()

     

     


    untill then this thread is just for bumping up post counts

     

     

    Pleas tell me this forum is grown-up enough not to care about postcounts.... 

  2.  


    Why roll your own and go through the growing pains associated with it when you can grab an enterprise solution off the shelf and integrate it? 

     

    In the case of Doctrine I'd say: because ORM shoiuld be chosen carefully, very carefully.

    In the case of any other off-the-shelf solution; depends on how much work it is to migrate.

     

    Why a homemade solution; because you can make it follow the mysql_* interface so you don't have to change any of your existing code. You could just search and replace mysql_ with mydbclass_ and that would be that.

  3.  


    I like the idea of a class with generic function names, because if there is ever another style to use (mysqlii?) we can just write up the proper functions inside of the existing class and they'll work without a hitch.

     

    You will always have your own class that wraps something, even PDO, because you'll always want to implement some logging, auditing, performance monitoring etc in the most central location, which will be the the database class.

     

     


    I know it's good for dealing with multiple types of databases (mysql, mssql, oracle) but this company will only ever be working with mysql, so I don't have to go overboard with considerations for that.

     

    PDO does nothing for supporting multiple databases except use the same function names for the various things you can do to a database. Every brand of database has it's own dialect and PDO does not translate that. Adding a database brand always requires separate PHP code.

     

    If you're going to move away from mysql_* then you might aswel go for PDO, which has a slightly more logical interface. (and that would be the only reason, for me :) )

  4.  


     Each time one group of data has been displayed I would like PHP to free the memory used and dedicate it to the display of the next group of data.

     

    Like McGyver said you'd have to tell more about the code, but...

     

    Once a group of data has been displayed you no longer need the variables that hold that group, so you can simply re-use the exact same variables, which will also reuse the memory.

     

    Roughly speaking, this will use a maximum of 10 bytes at any given time:

     

    $a = 'hello';

    echo $a;

    $a ' ='1234567890';

    echo $a;

    $a = 'Goodbye';

    echo $a;

     
    I have assigned 22 bytes to $a, but only a maximum of 10 at a time, so PHP will use 5 bytes for the first string, add 5 for the second, and release 3 bytes for the last string.
  5. The queryresult can be read using a loop, so you can put all the results in an array. Then for the left side you loop through the first four elements of that array, and for the right side you loop through the other four. Don't think too much about the problem, just do exactly what you want ro achieve: "stick the first four here, and the other four there."

     

    By the way, unless this is an extremely highperformance thing, you could also just run two queries, one for the left and one for the right: the first would do LIMIT 4 OFFSET 0  and the other: LIMIT 4 OFFSET 4

  6. The year1, year2, year3 columns smell like an error in the design, repeating columns are usually not as flexible as you might want.

     

    Your first question could be a simple as running an aggregate:

    SELECT id, SUM(year1), SUM(year2), ... FROM table GROUP BY id;

     

    The second question requires more rules, you have put A and C in the same row, and all the B's in the second, why can A and C be merged, but the B in year-2 cannnot?

  7. @mac_gyver: I was hoping for something more substantial than a possible floatingpoint error when one fails to use CAST(). :-)

     

    @mikosiko: That deals with mismachting values, not about the difference in speed when processing quoted values vs non-quoted values.

     

    Either way, this discussion should perhaps be a separate thread...

  8.  


    Do not quote numeric values. MySQL won't error if you quote numbers but you give it the overhead of converting strings to numeric types.

     

    Do you have a link to some documentation about that? Given that the quotes in an SQL string merely indicate where the content begins and ends I can't help but think that there is no measurable difference in performance.

  9.  


    In that case also i need to DELETE rows.

     

    No. Stop and think for a minute.

     

    What you need is *a* table that holds the records you want. That doesn't have to be the current table, it can be any table.

     

    So, you can create a NEW table, fill it with the data you *do* need: INSERT INTO newtable SELECT * FROM oldtable WHERE this=that AND foo=bar;

    and use that.

     

    If, for some magic reason you absolutely must work with the original table then the solution can stil be the same, you just have to compare the two tables to find the records you need.

  10. Older MySQL versions will not allow you to select from the same table you are deleting from.

     

    But you are getting yourself hung on the idea that you have to delete records. You don't. Al you need is a table that has the records you *do* need, and your XML can be generated from that.

  11.  


     So, quotes are required around all "text" type fields., but not around numeric type fields for example. 

     

    MySQL allows quotes around all fieldtypes, including numeric, and because quotes add a little bit more security it's better to allways quote all values in MySQL (and postgresql) queries.

    I've seen people build elaborate routines that were supposed to workout if the value should be quoted, only to find out later that the database actually didn' t care :-)

  12. It's usually easier to describe in SQL what you want to keep, rather than what you want to delete. What you want to delete is then simply "what you have - what you want to keep".

     

    If you add a new temporary table and fill it with the records you want to keep, then you can delete the unwanted records from the original table using a LEFT JOIN with the temporatry table.

     

    that said; I have rarly had a need to delete records, it is usally much better to build a view that filters all the unwanted records, or even to let the application decide which records it needs. Every record you delete has a tendency to become very important once you have deleted it :-)

  13.  


     for talk sake assume that the customer table has a MANU_ID.

     

    I cannnot , because that is not what you have in your tables.

     

    You seem to want to get all data about a customer, it's manufacturers, operatingsystems etc at once. This smells like a common misunderstanding  about how databases work.

    Each customer can have any number of manufacturers, operatingsystems etc. UNION, as you have notices, simply doesn't work for this. A JOIN on the other hand will return every combination of all record that match the ON clause, so if a customer has 4 manufacturers and 3 operatingsystems, you would get the customerdata 12 times. Not every usefull.

     

    I think the best thing you can do is simply use separate queries. if the number of queries is an issue then you should select multiple customers and manufacturers etc per query and merge them together in you application.

  14. Barand normalized the data before applying this query, as I suggested earlier.

    Basically he transformed the data from 

     

    id ball1, ball2, ball3 etc

    1, 5,7,9,...

     

    to:

     

    id, ballvalue, ballposition

    1,5,1

    1,7,2

    1,9,2

     

    which you can do using something like 

     

    CREATE TABLE random_normalized AS 

    SELECT * FROM

    (

    SELECT id, ball1 AS ball, 1 AS seq FROM random

    UNION ALL

    SELECT id, ball2 AS ball, 2 AS seq FROM random

    UNION ALL

    ...

    ) AS n;

     

    That table can then be used by Barand's query.

×
×
  • 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.