Current location: Hot Scripts Forums » Programming Languages » PHP » class problem


class problem

Reply
  #1 (permalink)  
Old 08-05-07, 07:21 AM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
class problem

I have one problem about a class
PHP Code:

<?php

/**
 * Hamed Page maker
 */
//Mysql have some functions that we can make them as a class
class db
{
    var 
$sql;
    
//for read mysql_query we use $db->sql();
    
function sql($sql)
    {
    
mysql_query($sql) or die(mysql_error());
    }
    
//for use mysql_fetch_array we use $db->fetch();
    
function fetch($sql)
    {
        
mysql_fetch_array($sql) or die(mysql_error());
    }
    
//for count rows we use $db->nums();
    
function nums($sql)
    {
        
mysql_num_rows($sql) or die(mysql_error());
    }    
}
?>
this is class and my code to call class
PHP Code:

<?php


/**
 * @author TEAM ViRiLiTY
 * @copyright 2007
 */

include "inc/class_mysql.php";
include 
"inc/config.php";
$db->sql("INSERT INTO `ugp`.`page` (
`pid` ,
`pagetitle` ,
`pagename` ,
`pagekeyword` ,
`pagedes` ,
`htmlcode` ,
`active` 
)
VALUES (
NULL , 'dssdsd', 'sddsds', 'sddsds', 'dsdsds', 'dsdsds', ''
);
"
);

?>
Reply With Quote
  #2 (permalink)  
Old 08-05-07, 08:05 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Where is your question?
__________________
The toxic ZCE
Reply With Quote
  #3 (permalink)  
Old 08-05-07, 09:37 AM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
Sorry I got this
Fatal error: Call to a member function sql() on a non-object in C:\xampp\htdocs\index.php on line 10
Reply With Quote
  #4 (permalink)  
Old 08-05-07, 10:21 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You need to create an instance of your class before any of the member functions/data will exist -
PHP Code:

$db = new db
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 08-05-07, 12:37 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks very good!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
object manager class / object class ther PHP 0 07-14-07 12:36 PM
conceptual problem: abstract class, interface or class UnrealEd Everything Java 2 05-12-07 07:30 AM
I need to pass this class Please Help! Negative6 Everything Java 1 05-03-07 06:55 AM
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
problem with classes filth PHP 4 07-04-05 04:39 PM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.