日本語:Dbal.sql build array

dbal::sql_build_array -- INSERT や UPDATE クエリを生成する.

説明
string dbal::sql_build_array ( string $query [, array $assoc_array ] )

例 #1 新しいデータを挿入
$sql_ary = array(   'somedata' => $my_string,    'otherdata' => $an_int,    'moredata' => $another_int );

$sql = 'INSERT INTO '. SOME_TABLE. ' ' . $db->sql_build_array('INSERT', $sql_ary);

$db->sql_query($sql);

例 #2 データを更新
$sql_ary = array(   'somedata' => $my_string,    'otherdata' => $an_int,    'moredata' => $another_int );

$sql = 'UPDATE '. SOME_TABLE. '   SET '. $db->sql_build_array('UPDATE', $sql_ary). '   WHERE user_id = '. (int) $user_id; $db->sql_query($sql);

例 #3 SELECT 文を生成
$sql_ary = array(   'somedata' => $my_string,    'otherdata' => $my_int,    'moredata' => $another_int );

$sql = 'SELECT some_field FROM '. SOME_TABLE. '   WHERE '. $db->sql_build_array('SELECT', $sql_ary); $result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result)) {   $template->assign_blockvars('some_block', array( 'SOMEDATA' => $row['somedata'], )); }

参照

 * Database Abstraction Layer
 * dbal.sql_build_query
 * dbal.sql_multi_insert

Dbal.sql_build_array