Use my sql instead of postgreSql
i want to use mysql instade of postgreSql.
I use example in professional PHP5 example but i got error. The code is below:
<?php
class widget{
private $id;
private $name;
private $description;
private $cdb;
private $hdb;
private $needUpdating=false;
public function __construct($widgetid)
{
//widgetid is the primary key of the record of database containing information for this object
//Create connection for database
include_once('class.DBClass');
$this->cdb=mysql_connect("localhost","rabby@localhost" , "rabby",1,1);
if(!is_resource($this->cdb)) {
throw new Exception("An Error occurred connecting to mysql");
}
$this->hdb=mysql_select_db('parts') ;
if(!is_resource($this->hdb)){
throw new Exception("An Error occurred connecting to database ");
}
$sql="SELECT * FROM `widget` where widgetid = $widgetid";
$result=mysql_query($sql,$this->hdb);
if(!is_resource($result)){
throw new Exception("An Error occurred selecting from database ");
}
if(!mysql_numrows($result))
{
throw new Exception("The specified widget does not exit");
}
$data=mysql_fetch_array($result);
$this->id=$widgetid;
$this->name=$data['name'];
$this->name=$data['description'];
}
public function __destruct()
{
if(!$this->needUpdating)
{
return ;
}
$sql="UPDATE `widget` SET `name` = '$this->name',
`description` = '$this->description' WHERE `widgetid` ='$this->id' LIMIT 1 ";
$result=mysql_query($sql,$this->hdb);
if(!is_resource($result))
{
throw new Exception("An error occure updating the table");
}
mysql_close($this->cdb);
}
function sayHellow(){
print "Hellow {$this->getName()}";
}
public function getName()
{
return $this->name;
}
public function getDescription()
{
return $this->description;
}
public function setName($name)
{
$this->name=$name;
$this->needUpdating=true;
}
public function setDescription($description)
{
$this->description=$description;
$this->needUpdating=true;
}
}
?>
neamulhuq
|