Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Thursday, December 27, 2012

Common MySql Field Data Types


MySql : Common Field Data Types:
By Stephon Unomon
Google +

 

CHAR() – Fixed length field between 0 and 255 characters that can store any type of data. The length of the field is set regardless of the size of the data placed into it.

DATE – Date in YYYY-MM-DD format.

INT – Whole numbers only.  The number of digits can also be specified in parentheses, but is not necessary.

TEXT – Variable length text-only field with a maximum length of 65535 characters.

TIME – Time in hh:mm:ss format.

VARCHAR() – Variable length field between 0 and 255 characters that can store any type of data.  Unlike the CHAR() type, the length of each VARCHAR() field is determined by the data placed into it.

 

So, knowing this, let’s decipher our code example from above.

 

<?php mysql_query(“

CREATE TABLE Employees

(open the query to the DB and make this table with Employees as the name)

 

(employee_id INT,

(make this field with employee_id as the name and allow only whole numbers)

 

first_name VARCHAR(50),

(make this field with first_name as the name, allow any input, and limit it to 50 characters in length)

 

last_name VARCHAR(50)”)

(make this field with last_name as the name, allow any input, and limit it to 50 characters in length)

?>

Once you get the basic concepts, data manipulation with MySQL is not difficult. Let’s dive in a little bit more to the way tables are laid out.
 
 
Save Time While Building PHP Applications
Check Out
The #1 PHP GUI Controls

Tuesday, December 25, 2012

MySQL Data Base Select Command - PHP For Beginners (MySQL)


Putting The Data In The Base
By Stephon Unomon
Google +

 

OK! We’re connected to a MySQL database! Far out! Now what? We need to put data IN to the database and use it!

 

So, here’s how we do it.

 

 

 

First of all, you have to select the database with the mysql_select_db() command.

 

<?php

mysql_select_db("my_db") or die(mysql_error());

?>
 

Tuesday, December 18, 2012

MySQL How To : PHP For Beginners Lesson 13

MySql How To
By Stephon Unomon
Google +
Making the connection to MySQL...
 

 
Here we will go over MySql as a part of the Beginner PHP Course.  This important to know so I put together a Mysql How To

First off, we need to be able to tell PHP to connect to a database before we can use it. The command is straight forward - mysql_connect().

 

<?php

$dbhost = "localhost"; // the db’s server

$dbname = "mysite_dbname"; // the db’s name

$dbuser = "mysite_dbuser"; // the db’s username

$dbpass = "password"; // the password for the user

mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error()); //connect to db or show error if failure

echo "Connected to database";

?>

Looking at the above code, everything is pretty self explanatory...except the “or die” thing. This is a method of handling errors. If for some reason PHP cannot connect to the database, the “or die(mysql_error())” part tells PHP to show us exactly what the error was. Most of the time it is human error - the wrong username, password, etc. was entered in the code. Check your work!
 
Hope You Enjoyed This Mysql How To