Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Moderated Pro PHP
|
Moderated Pro PHP This is a moderated forum for discussing advanced, professional level issues with PHP. Your posts will not appear until a moderator approves them. Posts that are not the right level for this forum will be responded to and you'll be asked to post them in the [url="http://p2p.wrox.com/sql-server-2000-20/9"]Beginning PHP[/url] forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Moderated Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2008, 01:41 AM
neamulhuq
Guest
 
Posts: n/a
Default 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
 
Old December 23rd, 2008, 09:14 PM
Authorized User
 
Join Date: Dec 2008
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

can you please post the actuall error message ?

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
php and postgresql crmpicco PHP Databases 0 February 23rd, 2007 08:34 AM
Postgresql Transactions satyr Pro JSP 0 March 23rd, 2006 08:31 AM
tomcat with postgreSQL alejo_torres BOOK: Professional Apache Tomcat 0 October 14th, 2005 09:15 AM
question regarding PostgreSQL Moharo MySQL 2 September 9th, 2003 02:38 AM
Upgrading Postgresql 7.1.3 to 7.3.3 ganesh15 PHP How-To 1 September 3rd, 2003 11:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.