PHPTriad: Play with MySQLMySQL database is a powerful, stable, easy, fond, and free database (maybe this free kind makes people interesting). MySQL too much using in the world. If you a web developer sure you know already or at least heard about its greatness. Luckily PHPTriad give this facility also for us to use, at least to learn. But author repeat it that this article not discussing MySQL Expert, because that outside this article bound. Is MySQL database difficult? Author’s answer it loud "no". PHPTriad completed works with MySQL database. So for you who need place to store or retrieve data, you may use this facility. Let’s continuing our numbering! And because author is a lazy man he would not configured it manually. If you a kind with author please follow step below!
If you want configured it again, you can click at that traffic light, mean that icon and choose "Show me". You can also change your username and password at “My.ini Setup” tab. See; now clear why author is a lazy man. Because with winmysqladmin we no need busy to arrange procedure and any other bored thing..
PHP and MySQL?Actually author confused, is he start with MySQL command first or we discuss PHP and MySQL connectivity first! Ok we discuss about connectivity first later we talk about it command line. Please follow the next step:
<?php $con=mysql_connect ('localhost','abu','poetra'); $db=mysql_select_db ('test'); if ($con) { echo "woi sudah konek!"; } else { echo "kok gak koknek ya?"; } ?>
Explanation: Lets us talk one by one (in general only) script above:
It function to connecting database on “localhost” with username “abu” and its password “poetra”. See, username and password basic on what you filled in “winmysqladmin”
It functions to choose database you have made at MySQL. Defaults in MySQL there are 2 databases that are “mysql” and “test”. Now it clear why author write using "test" database right?
MySQL Command Line! As other SQL (Structured Query Language) database, MySQL also completed by SQL command and syntax. Below we will discuss all the command from that syntax, but only in general. Author hope you understand and can using it. Now you sure confuse how to run console MySQL at PHPTriad? No need to confuse because there are 2 way to activate it. - Now you looking for “mysql.exe” in C:\Apache\MySQL\bin\mysql.exe directory! If you find it click twice. You can get what console you want directly. - Second way is by DOS Command. Start – Run – typing “cmd” – typing “C:\>\apache\mysql\bin\mysql.exe”. So you will get what console you want directly. Note: Author using Windows 2000, for you who are using Windows 9x, type "command" at run. If you now get in console mysql already, try to type the command below! mysql> show databases; Show databases command function to show the entire database in MySQL. And result will like this! +------------+ | Database | +------------+ | mysql | | test | +------------+ 2 rows in set (0.00 sec) This mean in MySQL there are 2 data base, which is “mysql” and “test”. Until now you sure are confusing why in database there are “mysql” database also? Later along with higher your knowledge, you will understand! Now we just continue. Mean we already know whatever database in MySQL. Let’s using "test" database to try our SQL command. How? mysql> use test; Database changed Now we already using "test" database. Look database changed message which mean database we used is changed be "test" database. Use nama_db; command function to change database! and author remind you, every order or query you made don’t forget to write “;” mark. Do you want to know what table in test database? Use show tables; command to see whole database. mysql> show tables; Empty set (0.00 sec) You see there are “Empty Set (0.00 sec)” message, this marked if "test" database has no table yet. Want to see how to open the table? Sure? Not asleep and boring yet? If you asleep and boring lets continue... just kidding ...) Type creates table nama_table; command to make table in test database. mysql> create table data ( id int (10) not null auto_increment, nama varchar (100) not null, email varchar (100) not null, phone varchar (20) not null, primary key(id)); Query OK, 0 rows affected (0.00 sec)
Actually we can type command above in the line like “create table data (id int (10) Not null auto_increment, nama varchar (100) not null, email varchar (100) not null, phone varchar (20) not null, primary key(id));” without press the "enter". This depends on our habit only. OK! Don’t make small thing a problem. Now it situation we have "data" table already and it fields on “test" database, Not believe? Now try again show tables; Command to see is our "data" table has been made.
Mysql> show tables; +------------------+ | Tables_in_test | +------------------+ | data | +------------------+ 1 row in set (0.00 sec)
Look your "data" table exist. Now the problem is how can we see the fields inside it? Let’s see it together. mysql> desc data; +---------+----------------------+------+-------+----------+--------------------+ | Field | Type | Null | Key | Default | Extra | +---------+----------------------+------+-------+----------+--------------------+ | id | int(10) | | PRI | NULL | auto_increment | | nama | varchar(100) | | | | | | email | varchar(100) | | | | | | phone | varchar(20) | | | | | +---------+----------------------+------+-------+----------+--------------------+ 4 rows in set (0.00 sec)
To see the fields in the table you can using describe or desc only. It is up to you whatever you like. From result of desc data command above we see the fields is “id”, “nama”, “email”, and “phone”. But the fields are empty still. You want to fill it? Or leave it empty.
Actually I want to teach you more than this, but because this tutorial is about PHPTriad installation only and not tutorial about PHP. Go and learn in http://ilmukomputer.com/berseri/ivan-php/index.php that will guide you pass the beginner period be expert.
IlmuKomputer.Com Abu Poetra |