doubledee — 2012-09-23T20:21:47-04:00 — #1
I have a table with 15-20 columns that is getting a little unwieldy because the columns no longer match what I feel is a "logical" order.
If I change the order of the columns - either by creating a new table or by using ALTER - will this break any of my existing queries or code?
That is, does either SQL or PHP care that the column order in my code/queries does not match the physical order of my tables?! :-/
guelphdad — 2012-09-23T21:04:15-04:00 — #2
how do you view your table other than with a SELECT clause? Why would it matter the physical order when you can determine what shows up with a SELECT clause?
I think you worry FAR TOO MUCH about minute things in your database(s), table(s), column name(s) etc. Focus on your work and don't sweat the small stuff.
r937 — 2012-09-23T22:11:50-04:00 — #3
unless you use (deprecated) ordinal position numbers in your ORDER BY clause, it will have no effect on sql
if you use arrays in handling your query results in php, with offset positions instead of column names in those arrays, you could mess up big time
doubledee — 2012-09-24T21:24:58-04:00 — #4
What about in a Prepared Statement like this...
// Find Articles. *
// Build query.
$q1 = 'SELECT section, heading, image, published_on, summary
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind variable to query.
mysqli_stmt_bind_param($stmt1, 's', $_GET['section']);
// Execute query.
// Store results.
// Check # of Records Returned.
// Articles Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt1, $section, $heading, $image, $publishedOn, $summary);
// Fetch below in loop...
r937 — 2012-09-24T21:38:33-04:00 — #5
i don't do php so i can't say with certainty, but it looks okay, you're referencing the result using the same column names and not positions
doubledee — 2012-09-24T21:49:45-04:00 — #6
P.S. Is it bad for me wanting to "pretty up" the order of my table columns? :-/
guido2004 — 2012-09-25T03:40:13-04:00 — #7
Bad? Not if you're doing it in your own time. If you were working for a boss, he might not be too pleased.
Lot of extra, useless work? IMO yes
cpradio — 2012-09-25T05:27:22-04:00 — #8
Changing the order of the columns in your table will not break this code because you are defining the order of the columns you want in the SELECT statement, which still match your bind_result statement. If you had used SELECT * instead of listing your column names, OR if you change the order of your column names in your SELECT statement, yes your code will break.
doubledee — 2012-09-26T21:49:06-04:00 — #9
Yep, it's my system.
doubledee — 2012-09-26T21:49:50-04:00 — #10
If you had used SELECT * instead of listing your column names, OR if you change the order of your column names in your SELECT statement, yes your code will break.
mittineague — 2014-09-20T02:59:56-04:00 — #11
This topic is now archived. It is frozen and cannot be changed in any way.