This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Monday, January 2, 2012

Formatting MySQL datetime field in PHP

If you would like to get a nice format on the datetime field stored in MySQL, use the following code:

<?php

    $datetime = strtotime($row_links['dateAdded']); // The date time field
    $formatDate = date("m/d/y g:i A", $datetime);
    echo $formatDate;

?>

This will output something like:

01/01/12 8:07 PM

If you want more formatting options for the date(), you can review the manual on PHP.net here.

Monday, February 14, 2011

Delete All Records in a MySQL Table – Quick Reference

Occasionally you may need to remove all records from a database table to reset the data. The following code is a quick reference to delete all of the records within a table. It can be copy/paste into a PHP page, then it will work after modify the reference to the database and/or tables.

This is just quick reference to remove all records from a database:

PHP Code:


$deleteSQL = "DELETE FROM inventory";
mysql_select_db($database_database, $databse);
$Result1 = mysql_query($deleteSQL, $database) or die(mysql_error());

Friday, April 18, 2008

Resetting the Auto Increment

Here is a little trick I have picked up in my travels… when you load information into a MySQL database that has an auto increment for the key, those keys can become quite large. Especially if you continue to delete/load records into the database.

You can use the following to reset the key (Or change it to whatever you want):

Perform this after a deletion…
$fixIt = "ALTER TABLE inventory AUTO_INCREMENT = 1";
mysql_select_db($database_experience, $experience);
$Result1 = mysql_query($fixIt, $experience) or die(mysql_error());