Using PHP with MySQL examples

I will continue to add to the php and mysql examples. These are just some simple examples. Remember just put them in between php tags and place the code in a php file. All of them you will have to add your username, password, database and table name(except for view tables).

Truncate a table

This will erase all data in your mysql table but keeps the structure.

$host="localhost"; // Host name
$username=" "; // Mysql username
$password=" "; // Mysql password
$db_name=" "; // Database name
$tbl_name=" "; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="TRUNCATE TABLE '$tbl_name' "; //might need to change the quotes
$result=mysql_query($sql) or trigger_error(mysql_error().$sql);
mysql_close();

Create a Table Example

This assumes you already created a database.

// Make a MySQL Connection
$con = mysql_connect("localhost", "user name", "password") or die(mysql_error());
mysql_select_db("database name") or die(mysql_error());

$sql = "CREATE TABLE newTableName
(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
username varchar(20),
passwd char(40),
email  varchar(100),
facebookID varchar(20),
tweetID varchar(20),
about varchar(300)
)";

mysql_query($sql,$con);

View mysql Tables

Scroll to the bottom see all the tables in your database. This is code produced from someone else. Props to that person.

Due to formatting issues I put it in a text file.

viewtables.txt

View Data in a mysql table

viewall.txt


Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on

  • wholesale nfl jerseys
  • wholesale nfl jerseys china
  • wholesale sports jerseys