0

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.

3
Contributors
17
Replies
18
Views
6 Years
Discussion Span
Last Post by morteza_ipo
0

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?

0

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 ?

Edited by pritaeas: n/a

0

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

Edited by Shanti C: n/a

0

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!

0

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.

0

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

Edited by morteza_ipo: n/a

0

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/

Edited by pritaeas: n/a

0

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');
0

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 ?

0

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

---

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

0

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

Edited by morteza_ipo: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.