Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ***Connection establish :
- #Mysql :
- $con = mysql_connect('Server Host Name','User Name' ,'Password');
- mysql_select_db('Database name',$con);
- #XML :
- $xml = simplexml_load_file("users.xml"); //This line will load the XML file.
- $sxe = new SimpleXMLElement($xml->asXML());
- ***View the details:
- #Mysql:
- <?php $query = "SELECT * FROM users";
- $result = mysql_query($query);
- while($resUsers = mysql_fetch_assoc($result)){
- echo $resUsers['name']
- } ?>
- #XML :
- $rows = count($sxe);
- for($i=0;$i<$no_rows;$i++){
- echo ($sxe->users[$i]->name);
- }
- ***Insert the details:
- #Mysql:
- $query = "insert into users(id,name)values($id,'$name')";
- $result = mysql_query($quesry);
- #XML:
- $no_rows = count($sxe);
- $query = $sxe->addChild("users");
- $query->addChild("id", $no_rows+1);
- $query->addChild("name", ($name));
- $sxe->asXML("users.xml");
- ***Edit the details:
- #Mysql :
- $query = "select * from users where id=".$edit_id;
- //and update query :
- $query_update = "update users set name = '$name' where id=$edit_id";
- $result = mysql_query($query_update);
- #XML:
- <?php $rows = count($sxe);
- for($i = 0, $length = $rows; $i < $length; $i++){
- if($sxe->users[$i]->id == $edit_id){ ?>
- <input value="<?php echo $sxe->users[$i]->name;?>">
- <? }
- //Update:
- $rows = count($sxe);
- for($i = 0, $length = $rows; $i < $length; $i++){
- if($sxe->users[$i]->id == $edit_id){
- $sxe->users[$i]->name = ($name);
- }
- }
- $sxe->asXML("users.xml");
- ***Delete the details:
- #Mysql :
- $query = "delete from users where id=".$edit_id;
- $result = mysql_query($query);
- #XML :
- $rows = count($sxe);
- for($i = 0, $length = $rows; $i < $length; $i++){
- if($sxe->users[$i]->id == $edit_id){
- unset($sxe->users[$i]);
- break;
- }
- }
- $sxe->asXML("users.xml");
- ***Database:
- CREATE TABLE `users` (
- `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
- `name` VARCHAR( 250 ) NOT NULL
- )
- #XML File:
- //(users.xml)
- <?xml version="1.0" encoding="iso-8859-1"?>
- <userdetails>
- <users>
- <id></id>
- <name></name>
- </users>
- </users>
Advertisement
Add Comment
Please, Sign In to add comment