Most of new programmers using the chain method in their code. Actually they just follow the tutorial on the book.
If you are new programmer, you need to read this simple post for better understanding.
After reading this post, I hope you know how chaining works and how to make chaining.
Let start from a case; I use a query case like this;
select id, country_name from country_table order by id desc
Let solve that case.
First, you need to create 'a chaining class';
class MySimpleQuery
{
static public function myQuery()
{
return new self();
}
public function select($field)
{
echo "select $field ";
return $this;
}
public function table($table)
{
echo "from $table ";
return $this;
}
public function order($field,$direction)
{
echo "order by $field $direction ";
return $this;
}
}
Now you want to call it right? This is how to call it;
$my_query = MySimpleQuery::myQuery()
->select('id, country_name')
->table('country_table')
->order('id','desc');
mysql_query($my_query);
If you echoing $my_query, you will see;
select id, country_name from country_table order by id desc
Well, that's it. You can develop above sample towards.
Langganan:
Posting Komentar (Atom)
Why I Built an AI Decision Support Copilot for Executives
For years, I’ve been building software — from blockchain exchanges to AI agents. But one problem kept repeating itself in every company I w...
-
This step-by-step guide will walk you through backing up your current iptables configuration and restoring it when needed. Prerequisites ...
-
Langkah 1: Identifikasi Container PostgreSQL Gunakan perintah docker ps untuk menemukan container PostgreSQL: docker ps Cata...
-
Pada saat pembuatan address pada walet Metamask atau wallet web3 lainnya, public key selalu tidak ditampilkan walaupun sebenarnya sudah dibu...
Tidak ada komentar:
Posting Komentar