Ad Code

Responsive Advertisement

Introduction My SQL With PHP

 Introduction My SQL With PHP

 





Before you really begin fabricating your data set contents, you should have a data set to put data into and read it from. In this part I will tell you the best way to make an information base in MySQL and set it up for the information. I will likewise start to tell you the best way to make the contacts the board information base. 


Information base Construction 


MySQL information bases have a standard arrangement. They are comprised of an information base, in which is contained tables. Every one of these tables is very separate and can have various fields and so on despite the fact that it is important for one information base. Each table contains records which are comprised of fields. 


Information bases And Logins 


The way toward setting up a MySQL information base differs from host to have, you will anyway wind up with a data set name, a client name and a secret key. This data will be needed to sign in to the information base. 


In the event that you have PHPMyAdmin (or a comparative program) introduced you can simply go to it to sign in with your client name and secret phrase. If not you should do all your information base organization utilizing PHP contents. 


Making A Table 


Before you can do anything with your information base, you should make a table. A table is a segment of the data set for putting away related data. In a table you will set up the various fields which will be utilized in that table. Due to this development, virtually all of a site's information base requires can be fulfilled utilizing only one data set. 


Making a table in PHPMyAdmin is straightforward, simply type the name, select the quantity of fields and snap the catch. You will at that point be taken to an arrangement screen where you should make the fields for the information base. On the off chance that you are utilizing a PHP content to make your information base, the entire creation and arrangement will be done in one order. 


Fields 


There are a wide assortment of fields and traits accessible in MySQL and I will cover a couple of these here: 


Field Type Description 


TINYINT Small Integer Number 


SMALLINT Small Integer Number 


MEDIUMINT Integer Number 


INT Integer Number 


VARCHAR Text (most extreme 256 characters) 


Text 


These are only a couple of the fields which are accessible. An inquiry on the web will give arrangements of all the field types permitted. 


Making A Table With PHP 





To make a table in PHP is marginally more troublesome than with MySQL. It takes the accompanying configuration: 


Make TABLE table_Name { 

Fields 


The fields are characterized as follows: 


fieldname type(length) additional data, 

The last field entered ought not have a comma after it. 

I will give full an illustration of utilizing these later in the part. 


The Contacts Database 


The contacts data set will contain all the conact data for the individuals you enter and the data will have the option to be altered and seen on the web. The accompanying fields will be utilized in the information base: 


Name Type Length Description 


id INT 6 A special identifier for each record 


first VARCHAR 15 The individual's first name 


last VARCHAR 15 The individual's last name 


telephone VARCHAR 20 The individual's telephone number 


versatile VARCHAR 20 The individual's portable number 


fax VARCHAR 20 The individual's fax number 


email VARCHAR 30 The individual's email address 


web VARCHAR 30 The individual's web address 


You might be asking why I have utilized VARCHAR fields for the telephone/fax numbers despite the fact that they are comprised of digits. You could utilize INT fields however I want to utilize VARCHAR as it will permit runs and spaces in the number, just as literary numbers (like 1800-COMPANY) and as we won't start calls from the web it's anything but an issue. 


There is one other thing you should know about in this information base. The id field will likewise be set as PRIMARY, INDEX, UNIQUE and will be set to auto_increment (found under Extra in PH 


PMyAdmin). The purpose behind this is that this will be the field identifier (essential and file) thus should be remarkable. The auto addition setting implies that at whatever point you add a record, as long as you don't indicate an id, it will be given the following number. 


In the event that you are utilizing PHPMyAdmin or an administration program you would now be able to make this in a table called contacts. 


Making The Table In PHP 


The accompanying code should be utilized to make this table in PHP. A portion of the code has not been covered at this point yet I will clarify it completely in the following part. 


  • $user="username"; 
  • $password="password";
  • $database="database"; 


mysql_connect(localhost,$user,$password); 


@mysql_select_db($database) or pass on( "Unfit to choose information base"); 


$query="CREATE TABLE contacts (id int(6) NOT NULL 

auto_increment,

first varchar(15) NOT NULL,

last varchar(15) NOT NULL,

phone varchar(20) NOT NULL,

mobile varchar(20) NOT NULL,

fax varchar(20) NOT NULL,

email varchar(30) NOT NULL,

web varchar(30) NOT NULL,

PRIMARY KEY (id),

UNIQUE id (id),

KEY id_2 (id))"; 


mysql_query($query); 

mysql_close(); 


Enter your information base, MySQL username and MySQL secret phrase in the proper situations on the initial three lines above. 




Post a Comment

0 Comments