In this file all atribute readed because every thing same but one
atribute <Rent Per="Week">200.00</Rent> in different method and
<Rent Per="Week"> contian two conditions one is Rent per Week and other
will Rent per month.
<Rent Per="Week">200.00</Rent> in this lines we fatch 200.00 in our
databse but we also want to fatch "week" in our database.
We have write a php file to fatch data from XML to mySQL wich working
fine instead of <Rent Per="Week"> issue.
My PHP file code is as:
PHP Code:
<?php
define("DB_HOST","localhost",TRUE); // database server name
define("DB_USER","root",TRUE); // database user
define("DB_PASS","1234",TRUE); // database user's password
define("DB_NAME","xml",TRUE); // database name
$TAG = "EXTRA";
$id = 0;
//Initialize the XML parser
$parser=xml_parser_create();
//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
global $TAG;
switch($element_name)
{
case "PROPERTY":
echo "<br />[Property]";
$TAG = "PROPERTY";
break;
case "REFNUMBER":
$TAG = "REFNUMBER";
break;
case "NUMBER":
$TAG = "NUMBER";
break;
case "STREET":
$TAG = "STREET";
break;
case "ADDRESS3":
$TAG = "ADDRESS3";
break;
case "ADDRESS4":
$TAG = "ADDRESS4";
break;
case "POSTCODE":
$TAG = "POSTCODE";
break;
case "AREA":
$TAG = "AREA";
break;
case "TYPE":
$TAG = "TYPE";
break;
case "BEDS":
$TAG = "BEDS";
break;
case "RECEPS":
$TAG = "RECEPS";
break;
case "GARAGE":
$TAG = "GARAGE";
break;
case "PARKING":
$TAG = "PARKING";
break;
case "GARDEN":
$TAG = "GARDEN";
break;
case "BALCONY":
$TAG = "BALCONY";
break;
case "FLOOR":
$TAG = "FLOOR";
break;
case "AVAILABLE":
$TAG = "AVAILABLE";
break;
case "RENT":
$TAG = "RENT";
break;
case "DESCRIPTION":
$TAG = "DESCRIPTION";
break;
case "COMMENTS":
$TAG = "COMMENTS";
break;
case "PHOTO1":
$TAG = "PHOTO1";
break;
case "PHOTO2":
$TAG = "PHOTO2";
break;
case "PHOTO3":
$TAG = "PHOTO3";
break;
case "PHOTO4":
$TAG = "PHOTO4";
break;
case "PHOTO5":
$TAG = "PHOTO5";
break;
case "PHOTO6":
$TAG = "PHOTO6";
break;
case "PHOTO7":
$TAG = "PHOTO7";
break;
case "PHOTO8":
$TAG = "PHOTO8";
break;
case "PHOTO9":
$TAG = "PHOTO9";
break;
case "MAP":
$TAG = "MAP";
break;
case "MOVIE":
$TAG = "MOVIE";
break;
case "URL":
$TAG = "URL";
break;
default:
$TAG = "EXTRA";
}
}
//Function to use at the end of an element
function stop($parser,$element_name)
{
echo "";
}
//Function to use when finding character data
function char($parser,$data)
{
global $TAG;
global $id;
//Specify element handler
xml_set_element_handler($parser,"start","stop");
//Specify data handler
xml_set_character_data_handler($parser,"char");
//Open XML file
$fp=fopen("rentman.xml","r");
//Read data
while ($data=fread($fp,4096))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
//Free the XML parser
xml_parser_free($parser);
?>
I also use a class for this purpose as below:
PHP Code:
<?php
class db {
function connect() {
$die = false;
$link = @mysql_connect(DB_HOST, DB_USER,DB_PASS) or
($die = true);
if($die){
echo '<h3>Database connection error!!!</h3>';
echo 'A connection to the Database could not be
established.<br />';
echo 'Please check your username, password,
database name and host.<br />';
echo 'Also make sure <i>mysql.class.php</i> is
rightly configured!<br /><br />';
exit();
}
mysql_select_db(DB_NAME);
return $link;
}
// Returns an array that corresponds to the fetched row
function fetch_array($query) {
$query = mysql_fetch_array($query,MYSQL_ASSOC);
return $query;
}
// To Execute Sql Query
function query($sql,$res) {
$query = mysql_query($sql) or die(mysql_error());
return $query;
}
// Retrieves the number of rows from a result set
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
// Get the number of affected rows by the last INSERT, UPDATE
or DELETE query
function affected_rows($query) {
$query = mysql_affected_rows();
return $query;
}
}
?>
Now in this situation I also want to fatch data of this attribute <Rent
Per="Week"> in my databse. In thi I want to store "week" in my databse.
For this purpose please write any quote within my quote and let me know