Hello.

I want to create this address with php!

<?php
$a = new dbclass();

$a->tablename->fieldname1('fieldvalue1')->fieldname2('fieldvalue2');

$a->delete(); //<<-- example!

$a->insert(); //<<-- example!

$a->update(); //<<-- example!

?>

Please help me how to create class with this feature.

thanks a lot.

Thanks for helping!

But

I cannot create function for any tables and any fields of that!

I want to create a function when I send 'tablesname' or 'fieldsname' that can process them!

Are you understand?

It shows you how to create a function. It is up to you to define it's capabilities.

What is it you want to happen when you send a table name ?

pass table name, fields as parameters to function declaration,
and write db query in your function definition which is in class.
try coding ...

For example : I want to delete a row when field1 equal 5:
In this:

<?php
$row = new db();
$row->tablename->field1('5');
$row->delete();
?>

I say again!
I cannot create function for any tables and any fields!

thanks a lot!

The way you want it is a bit weird, but it should be possible to write classes that work in this way. However, it is a bit too extensive to start writing code for you.

I written this!
But this is not professional and very simple!
This is limited!

<?php

class db
{
    private $condition;
    function __call($table,$argv)
    {
        $this->condition = end($argv);
        array_pop($argv);
        $connection = mysql_connect('localhost','root','136');
        mysql_select_db("student",$connection);
        $fields;
        foreach($argv as $value)
        {
            $fields .= $value . ",";
        }
        $fields = substr($fields,0,strlen($fields)-1);
        $query = mysql_query("SELECT ". $fields ." FROM ". $table ." WHERE ".$this->condition);
        $row = mysql_fetch_array($query,MYSQL_ASSOC);
        return ($row);
        mysql_close($connection);
    }
}

$obj = new db();
// $row = $obj->table_name('field1' , 'field2' ,'field3'..... , 'condition'); <<-- you can write any tables!
$row = $obj->pages('topic','text','id=21');
echo "Topic: ".$row['topic']."<br>";
echo "Text: ".$row['text']."<br>";
?>

Return:

Topic: test
Text: this is new

This is very simple!

Help please!

how to create this ?

$obj -> database -> table ('fields','conditions') -> database2 -> table2 ('fields','conditions');

Means how to send that to class?

thanks again

This is very hard to create (let alone debug), you'd need every function to return an object. In my opinion you may want to rethink how you want to do things.

How did you get to wanting that syntax ? It looks like jQuery. Or are you perhaps looking for something like this: http://phplinq.codeplex.com/

I wrote that!

Reading book.
Surfing in the Internet.

I know you wrote that. All I'd like to know is *WHY* you want something like this:

$obj -> database -> table ('fields','conditions') -> database2 -> table2 ('fields','conditions');

I want to access to database with less code!

Okay. I understand that. Trying to create such structure, involves writing a lot of code to get that working. So in the end you'll be writing much more code altogether. Why not use mysqli or pdo ?

mysqli,PDO is very good!
I see for the first!

---

Pear? Pear is good?
-------

Yes, PEAR contains a lot of useful packages, for example MDB2 for data access.

I have a site!
I installed pear from cpanel!
How to use pear after the installing?

Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.