Date/Time sql

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

hey,
Im planning to create a column in a table named "news" to have a date/time of post.

Now whats the actual name of the date and time and also will it show as:

dd/mm/yy hr.min??


I was thinking:

Code: [ Select ]
$SQL[] = "CREATE TABLE gs_news (
Date/Time varchar(255) Default,
  1. $SQL[] = "CREATE TABLE gs_news (
  2. Date/Time varchar(255) Default,


??

I dont want to test it out yet, i want to make sure everything is fine first then see if it works.


Goal: create a page that will install database tables for me.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

Also another question: What is more efficient?

1) inserting an image as a blob field in to a mysql database...

or

2) uploading an image to a specific directory and then just adding the link to the field.
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Time question...

simply use PHP's time(); function to generate a Unix timestamp (number of seconds since 00:00 Jan 1st 1970). Store this in the database. Then you can more easily order your results by age.

Use PHP's date(); function to format it when you want to actually display it.

Images : storing in files is much more efficient, especially if you have a lot of bigger (over 20KB or so) images, and a lot of people accessing them.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

Thanks axe!
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

im trying to make a script that will auto make tables etc on to a mysql database.

here is a snippet, please tell me if im going in the right direction.

PHP Code: [ Select ]
 
<?PHP
 
   $location = "localhost";
 
   $username = "";
 
   $password = "";
 
   $database = "";
 
   $conn = mysql_connect("$location","$username","$password");
 
 
 
   if (!$conn) die ("Could not connect MySQL");
 
   mysql_select_db($database,$conn) or die ("Could not open database");
 
 
 
 
 
// Insert tables in to the sql database.
 
$SQL[] = "CREATE TABLE gs_admin (
 
 IP_ADDRESS varchar(32) NOT NULL default '',
 
 Date_Time Date/Time(255) default NULL,
 
 username varchar(40) default NULL,
 
 password varchar(32) NOT NULL default '',
 
);";
 
 
 
$SQL[] = "CREATE TABLE gs_member (
 
 ID varchar(32) NOT NULL default '',
  1.  
  2. <?PHP
  3.  
  4.    $location = "localhost";
  5.  
  6.    $username = "";
  7.  
  8.    $password = "";
  9.  
  10.    $database = "";
  11.  
  12.    $conn = mysql_connect("$location","$username","$password");
  13.  
  14.  
  15.  
  16.    if (!$conn) die ("Could not connect MySQL");
  17.  
  18.    mysql_select_db($database,$conn) or die ("Could not open database");
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // Insert tables in to the sql database.
  25.  
  26. $SQL[] = "CREATE TABLE gs_admin (
  27.  
  28.  IP_ADDRESS varchar(32) NOT NULL default '',
  29.  
  30.  Date_Time Date/Time(255) default NULL,
  31.  
  32.  username varchar(40) default NULL,
  33.  
  34.  password varchar(32) NOT NULL default '',
  35.  
  36. );";
  37.  
  38.  
  39.  
  40. $SQL[] = "CREATE TABLE gs_member (
  41.  
  42.  ID varchar(32) NOT NULL default '',
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

at the end its like:

PHP Code: [ Select ]
 
  description varchar(50) NOT NULL default '',
 
  PRIMARY KEY  (id)
 
);";
 
echo ('all done');
 
}
 
else
 
{
 
echo ('couldnt do it');
 
 
  1.  
  2.   description varchar(50) NOT NULL default '',
  3.  
  4.   PRIMARY KEY  (id)
  5.  
  6. );";
  7.  
  8. echo ('all done');
  9.  
  10. }
  11.  
  12. else
  13.  
  14. {
  15.  
  16. echo ('couldnt do it');
  17.  
  18.  


As you can see im new to this.
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

If you really want to make a install thing, and your sort of new to MySQL, you should use phpMyAdmin to create all your tables and then just export it all and copy the code from there. That way you know you have not made any stupid mistakes that could be very annoying while creating your install script.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

Yeah very true, i created 6 pages of plans just for this script.

1) Need to check all files and folders are in place on server,
2) then i got to add a form, etc etc

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 68 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.