#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    730
    Rep Power
    0

    How To Grab Mysql Tbl Column Names ?


    Folks,

    I'm trying to grab the column names. How to do this ?
    Ok, as a beginner, let me think like a pro.
    Imagine I suddenly change tbl column names. Now, in the php script, gonna have to manually update those lines where the column names are referenced or mentioned. Can't be doing all this on hundreds of lines and so best write a script so it will do all the grabbing and updating on the appropriate lines (so to speak) via the function's value.
    Here's my nasty nasty attempt:
    PHP Code:
    <?php 

        $sql 
    "SHOW COLUMNS FROM users";
        
    $result mysqli_query($conn,$sql);
        while(
    $row mysqli_fetch_array($result)){
        ${
    $row['Field']} = $_SESSION["{$row['Field']}"]."<br>";
        echo ${
    $row['Field']}."<br>";
        echo 
    $_SESSION["{$row['Field']}"]."<br>";
        }
        
    /*
        $sql = "SHOW COLUMNS FROM users";
        $result = mysqli_query($conn,$sql);
        while($row = mysqli_fetch_array($result)){
        $row = $_SESSION["{$row['Field']}"]."<br>";
        }
        
        $_SESSION["name"] =  "Niklesh";
        $row = ["Field"=>"name"];
        ${$row['Field']} = $_SESSION["{$row['Field']}"]."<br>";
        echo $name;
        */
        
    ?>
    Look at the 2 commented parts to get an idea how many other ways I attempted. None are working. The code I have now really should have worked. Anyway, I tried my best. Let's see what you got up your sleeves!

    Thanks!
  2. #2
  3. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,739
    Rep Power
    9646
    Originally Posted by UniqueIdeaMan
    Imagine I suddenly change tbl column names. Now, in the php script, gonna have to manually update those lines where the column names are referenced or mentioned. Can't be doing all this on hundreds of lines and so best write a script so it will do all the grabbing and updating on the appropriate lines (so to speak) via the function's value.
    No. No no no no no no no.

    That is stupid. Don't do it.

    The answer to your problem is that there is no problem in the first place: don't change the column names.

    And if you would have to touch "hundreds" of lines then your code needs refactoring.
    Last edited by requinix; April 11th, 2018 at 12:02 AM.
  4. #3
  5. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,393
    Rep Power
    2105
    Requinex is 100% right.

    Think about it this way...

    Sure, you can change column names in your database (ps: possible, but don't do it - ever), and then your example will change along with that.

    BUT... Where are you actually going to use those fields? How would you keep track of them when you change the name of the column? User a 'users' table as an example, how would your code know which field is for first name, last name, username, etc? It could be literally any column. What type of data is stored in ${row ['field']}? How does that relate to how you need to use that data?

    Just do as requinex said and forget about this completely. Even from you, this is a terrible idea.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    730
    Rep Power
    0
    Thank you Requinix and Catacaustic!

    I am reading your replies 4 days later. I am glad Requinix is checking out my threads now and then.
    I will give you both respects and won't do on my current project what I originally intended to do because since this project is for the public welfare (erase poverty) then I can't afford to ignore seniors advice.
    However, saying all this, I still want to learn how to grab mysql table column names for playing & experimenting purpose. Just to satisfy my curiosity. Also, I want to demonstrate to you guys what I really meant as I get the feeling I have failed to portray to you all what I really meant or wanted to do.
    And so, for playing & experimenting's sake, let's play around a little.
    And so, care to explain where I am going wrong in my code ? Any code sample would be appreciated.

    Thanks!

    EDIT:
    Catacaustic, you said:
    "how would your code know which field is for first name, last name, username, etc?"
    That brought sense into me. You are right.
    But, a solution immediately rose in my mind.
    I once built a .exe bot with Ubot. Do you know what you have to do to get Ubot to build bots that auto fill-in forms ?
    We have to feed the bot each input field's "innertext" or "outerhtml" for the bot to identify the input fields.
    So, if a field is labeled "First Name" and it's name (html) or id is "first_name", then we'd program the bot to search for that particular input field who'se "name" or "id" is "first_name" and then dump the value from the #first_name vairable onto it to auto type the first name into the "First Name" labeled input field.
    But guess what ? For each website's form we had to program like that. Build different bots for different websites as all website's form did not have the same "name" or "id" or "outerhtml".
    Now imagine you have to build something like Senuke for your bot where you want it to auto signup users to hundreds of social networks. You're gonna have to build hundreds of bots or if you build one bot to register you to hundreds of social networks then you're gonna have to code it hundreds of different ways to deal with hundreds of different sites' forms.
    But as you know, I am very clever, even though a beginner programmer. At the very beginning of my Ubot career, I started building a bot that no matter what site's webform you set it to, it will search for a webform on the page you set it to.
    It will scrape all html between "<form" and "</form>". And then it will scrape all outerhtml and then using wildcard it will try sniffing for variations like ....

    lastname
    last_name
    surname
    sur_name

    And when it finds any of these variations it will automatically identify that as the input field where you input your surname. Then it will associate the surname/last name variable and dump it's value there.
    I programmed that bot to work on any website. So, you feed it a list of signup form's urls and it will auto navigate to them and start sniffing for what I just mentioned. Now, isn't that clever for a beginner botter ?
    Don't worry. I never released the bot nor engaged it in spam. There were one or two misfires and I put the project on hold for other less complicated bot projects.
    Now, you understand. When I build bots. I don't want to build bots that are dedicated to work on a limited number of sites. I build them to work on any website. Even those websites I never heard of. AI. Superintelligent AI.
    And you people have already got the wind of my nature. I try to run before I can walk. trying to do the same with php. Build clever scripts. No. Not trying to build smap bots. If I did, I'd be using cURL and asking you questions related to cURL.
    No. I am trying to be a little clever and build a super intelligent php script that deals with my site. Deals with my mysql tbl intelligently. So, if it sniffs the column names aren't what I programmed it by default then using the wildcard variation technique it would figure-out which column is for what.
    Ofcourse, if I totally change the column name who's variations don't exist in the php script's variations list then the super AI would become super stupid AI. I know that unless I feed it all the dictionary words and their synonyms and use threads to go through the list superfast to find matches. So, don't bother explaining this to me. I am not stupid. Do have common sense in this field.
    One thing though. I do hope from now on you think that: "Unique Idea Man is not a total beginner in programming. He isn't stupid. Does have some ideas. Clever ideas. And not totally naive. Even though he does clumsy things with php. And that is due to him not knowing the language that much.".
    I would then say: All fair & square!

    Mmm. An idea has come into my head. How-about building a super AI with php ? But ofcourse, not for spamming purposes. So, what kind of super AI can I build that can think for itself, like the semi-thinker .exe bot I built ? I say "semi-thinker" because it wasn't that intelligent in my opinion but it was unique in the sense that these type of .exe bots don't exists and if they do then they are very rare AND built by programmers with yrs of experience and not some beginner or amateur. And so, in that sense, I lived-up to my username in the Ubot forum which was "Unique Bot".
    Now, I want to live-up to my Username here which is Unique Idea Man and not Unique Idiot like some of you think. Wait till I dream-up some clever php tool and have you guys gaping at it's performace with your mouths wide open and your cigars dropping off your lips. Lol!
    I will have this thought at the back of my head. To dream-up a super AI php tool. Wish me luck!
    Maybe, I try building a web crawler to outsmart google ? If I manage to do that, then my searchengine would be the best in the world and google will become damp. That'll be the day!
    (It's as if I can see Requinix rolling his eyes and Catacaustic nodding his head "when will he learn or wise-up ?").
    But, one day, I will prove to you my ideas' worths.
    Last edited by UniqueIdeaMan; April 14th, 2018 at 01:38 PM.
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,925
    Rep Power
    4554
    Dumbass over here did some pattern matching on strings and thinks he built skynet! lol...

    Y'all seeing this?
    -- Cigars, whiskey and wild, wild women. --
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    730
    Rep Power
    0
    Originally Posted by Sepodati
    Dumbass over here did some pattern matching on strings and thinks he built skynet! lol...

    Y'all seeing this?
    Yeah! They are seeing it! I did tell you all that, in my opinion it was not good but I reckon for an amateur or a beginner then that kind of thinking is way up ahead!
    Here's a challenge! I will, GOD WILLING, make more money with my php venture in a single yr than you ever made with your entire php career. How about that for calling me a dumb *** ? I just spent praising you on another thread of mine and I now find you calling me a dumb ***! Oh man!
    Ok Sepo, since you called me a dumb ***, tell me, how much you're gonna pay me if I prove to everyone here that I am making more money with php compared to you ? And, all learning php from you and from this forum right under your nose ? WIll you then eat your words ?
    Show me, how much you have made with php. How have you put use to it to help the public or even your humbleself. Keep on the cricism because one day it will backfire on you. The more you talk the more it will fall back on you. Backfire.
    I'm not flaming you. Not gonna flame you. You're still in my good books. You have helped me get over obstacles with your hints when nobody else helped. I still wan to make you earn $$$ with my ideas. Nothing has changed.

    Actually, see if you can shed some light here and I'll forget what you just said:
    Paid Vps Host Users
    Last edited by UniqueIdeaMan; April 14th, 2018 at 03:07 PM.
  12. #7
  13. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,925
    Rep Power
    4554
    Don't forget what I said. If you do well, good on you. I'll happily eat crow.

    I haven't worked or made money with PHP since 2005, up until this last October or so. Did some PHP work at my job, so technically I got paid a months work, then.
    -- Cigars, whiskey and wild, wild women. --
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    730
    Rep Power
    0
    Originally Posted by Sepodati
    Don't forget what I said. If you do well, good on you. I'll happily eat crow.

    I haven't worked or made money with PHP since 2005, up until this last October or so. Did some PHP work at my job, so technically I got paid a months work, then.
    Ok, I won't forget it. I'll see if I can build something like Skynet or whatever it is. Name rings a bell. Let me google and see what it is before I open my big mouth! Thanks Michigan man! Thanks for being honest! I am more than ever convinced to make you one of the first members of my php ventures and earn you money.
    But tonight, like lastnight I'm gonna be busy looking more into vps hosts to gain some experience on them. Once that is finished then my 14 mnths wait is up!
    Wish me luck!
    Btw, since you haven't earned a living out of php then it should not be too hard for me to get you to earn a few $$$ with my php ventures.
    I'm gonna feel proud when you folks drop me a line and say: "Dude, we really thought you were just a big talk. Because you're crap at php or programming altogether, we thought your'e crap with your ideas too! But you proved us wrong!"

    Sepo, are you the kind of guy that prowls the blackhat forums ? If so, then you're probably intelligent in internet marketing (white hat tactics). In that case, you can probably help Catacaustic figure-out what my online business model is:
    http://forums.devshed.com/outhouse/9...ml#post2984917
    Last edited by UniqueIdeaMan; April 15th, 2018 at 12:34 PM.
  16. #9
  17. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,925
    Rep Power
    4554
    Eat a ****.
    -- Cigars, whiskey and wild, wild women. --
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    730
    Rep Power
    0
    Originally Posted by Sepodati
    Eat a ****.
    DOn;t understand what you mean, pal!
  20. #11
  21. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,656
    Rep Power
    1822
    Originally Posted by UniqueIdeaMan
    DOn;t understand what you mean, pal!
    He has concerns over your diet, so is suggesting a change in provender that will alleviate any stress and issues you may have ...
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo