AJAX MySQL Step By Step Tutorial - Part 1: To retrieve data from MySQL, what we need just transform array data from MySQL to XML use DOM.
For practice, create a database named "test". You can use phpMyAdmin or use line codes such as:
<?
//the example of making MySQL database
//create.php
$conn = mysql_connect("localhost","root","admin");
if($conn){
echo("Connection is succeed");
}else{
echo("Connection is fail");
}
$make = mysql_create_db("test");
if($make){
echo("Database data_root succeeds in making");
}else{
echo("Database data_root fails in making");
}
?>
In this practice, we create a table named "books". You can execute this query:
CREATE TABLE `books` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`author` varchar(60) NOT NULL,
PRIMARY KEY (`id`)
)
Such as:
<?
mysql_connect('localhost','root','admin');
mysql_select_db('test');
$sql = "CREATE TABLE `books` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`author` varchar(60) NOT NULL,
PRIMARY KEY (`id`)
)";
mysql_query($sql) or die(mysql_error());
?>
How to create use phpMyAdmin, you can read at this post.
Last, enter sample data such as this query:
INSERT INTO `test`.`books` (
`id` ,
`title` ,
`author`
)
VALUES (
NULL , 'PHP Undercover', 'Wiwit Siswoutomo'
), (
NULL , 'PHP Enterprise', 'Wiwit Siswoutomo'
);
Next, we create XML from this data use DOM.