Question about mySQL SELECT query and '*'
#1

When using 'SELECT * FROM ...' and then using mysql_fetch_field_row, my server crashes. When using 'SELECT Level FROM ...' however then getting the 'Level' field with mysql_fetch_field_row, it works fine. Does * mean nothing or all? I'm fairly certain it selects everything. Why does it crash? Using BlueG or Gtstylezzzzzzzzzzzzzzz or whatever's plugin.
Reply
#2

Yes, the star selects everything. But as the name implies, mysql_fetch_field_row is to be used to fetch the data from a single field. If you're looking to get more data from different fields, you're better off using mysql_fetch_row and splitting the result afterwards with sscanf.
Reply
#3

But what I'm saying is, if I need 100 fields, if I do

SELECT field1, field2, field3 etc.

it's going to need a massive string. Can't I just do

SELECT * FROM x ...

Then get the fields with the function?
Reply
#4

How exactly do you execute your querys?

I mostly do it like this when I'm required to get a big amount of columns:
Код:
mysql_query("SELECT * FROM `users`");
mysql_store_result();

while(mysql_retrieve_row()) {
    mysql_fetch_field_row(variable, "name");
    /*
     * more code
     */
}

mysql_free_result();
This never crashed my server even though my users table
has something between 50 and 100 columns.


It would be good if you posted the relevant part of your code,
because the error maybe is hidden somewhere else.
Reply
#5

Quote:
Originally Posted by MP2
Посмотреть сообщение
But what I'm saying is, if I need 100 fields, if I do

SELECT field1, field2, field3 etc.

it's going to need a massive string. Can't I just do

SELECT * FROM x ...

Then get the fields with the function?
If you don't want to load the data in a specific order or exclude some fields from being loaded, sure you can use * instead of listing field names. However I have switched to listing the fields, it also helps when you're adding a new field or for general database compatibility.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)