Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2012
    Thanked 0 Times in 0 Posts

    How to create a table in PHP

    I need to create a table in PHP.
    I've never done before!
    I always use other code like Wordpress or something.

    What's the best way to do?

    I have a Linux server.
    Use Cpanel?
    Use PHP code?

    EDIT: the primary key column needs to be a IP addresses.
    I have 2 concerns...
    Firstly, the addresses will only be IP4 ones, like: (just made that up).
    What format should this be? Text?

    Secondly, later... I need to store IP6. This would be something like: 2011:0db8:81a3:0000:0000:8a2e:0670:7434
    Any thoughts in regards this?


    PS... just thought of something... if I create a table using another language, is it different to one created in PHP?
    Last edited by OM2; Aug 18th, 2019 at 03:01 AM.

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Thanked 165 Times in 160 Posts
    How about telling us about the real problem you are trying to solve.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  3. #3
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    West Des Moines, Iowa
    Thanked 1,090 Times in 1,086 Posts
    Use Cpanel
    Yeah, I've always found that to be the easiest way. You should be able to copy the resulting PHP for future use.
    IPv4 and IPv6 can be saved as VARCHAR. Check INET6_ATON(expr) in manual https://dev.mysql.com/doc/refman/5.6...ion_inet6-aton
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  4. #4
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 530 Times in 516 Posts
    I always have in my programs a installer that creates the tables. Dicking around at the command line or phpMyAdmin or any other way doesn't give you a copy by which you can install it easily.

    That part of my installer is always the FIRST thing i do when buiding anything DB driven, as part of establishing my DB structure. Write it as code because if you plan on installing it more than once, you're going to need that code anyways.

    Let's assume you're using PHP and $db is a connected PDO object, and we're making a typical 'base' user table. (aka not stuffed with the stuff we DON'T access or update on every page -- that stuff goes in another table hence the "relational" part of relational databases)

    	CREATE TABLE users (
    		username VARCHAR(63) UNIQUE,
    		password VARCHAR(128), # big enough for SHA512/whirlpool
    		created DATETIME DEFAULT NOW(),
    		last_login DATETIME,
    		last_access DATETIME,
    		INDEX (username)
    It's just a query like any other query.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts