▼  Site Navigation Main Articles News Search  ▼  Anime + Manga Anime Reviews Anime Characters Gallery Screenshots Manga Reviews  ▼  Misc Links to Webcomics Bible Quotes About Older Musings
site version 7.3
MySQL –– traverse database
written by: admin


Date Written: 9/17/07 Last Updated: 9/29/13

This simple code will allow you to traverse your database and alter the table as you wish.  Provided you know how to write queries.

<?php
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
mysql_select_db("mysql_user",$conn)  or die(mysql_error());
$res = mysql_query('SHOW COLUMNS FROM tablename', $conn);
while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
printf("%s", "$row[0]<br>");  
}
?>
Below are a few examples of mysql queries you can make:

CREATE TABLE tablename(
(ID INT NOT NULL AUTO_INCREMENT,
summary TEXT,
date DATETIME,
PRIMARY KEY(ID))


basic commands:

SHOW TABLES

SHOW DATABASES

SHOW COLUMNS FROM tablename

SELECT cols FROM tablename WHERE ID = 3

SELECT * FROM table ORDER BY ID DESC LIMIT startnumber, numberofrows
("limit startnumber, numberofrows" needs to be the last thing listed)

ALTER TABLE tablename ADD columnname TEXT NULL

DELETE FROM tablename WHERE ID=3


TAGS: mysql
copyright 2005–2024