在Drupal 7中插入查询

时间:2013-07-01 10:52:12

标签: drupal drupal-7

 $table_name = 'tbl_users';
 $data = array('datetime'=>'NOW()',
                'ipadress' => $ipaddress, 
                'name' => $name,
                'dob' => $dob, 
                'nationality' => $nationality, 
                'address' => $address, 
                'city' => $city, 
                'state' => $state, 
                'pincode' => $pincode,
                'phone' => $phone,
                'email' => $email,
                'mobile' => $mobile,
                'weight' => $weight,
                'height'=> $height,
                'marital' => $marital,
                'degree' => $degree,
                'institute' => $institute,
                'special' => $special,
                'yearofpaas' => $yearofpaas,
                'grade' => $grade,
                'emplyment_history' => $emplyment_history,
                'merits' => $merits,
                'major_achivements' => $major_achivements,
                'interview_attended' => $interview_attended,
                'details' => $details,
                'minctc_position' => $minctc_position,
                'cv_file' => $cv_file,
                'declaration' => $declaration);
echo "<pre>";
print_r($data); 
drupal_write_record($table_name, $data);

我有这个插入查询,但不知何故记录不会进入表..任何人都可以帮助我...在查询中是什么问题?????

3 个答案:

答案 0 :(得分:1)

你传入NOW()作为一个字符串,这是行不通的。请尝试改为:

$data = array('timestamp' => date("Y-m-d H:i:s"),

答案 1 :(得分:1)

仅当my_module.install文件中存在表模式时,

drupal_write_record才有效。

here:drupal_write_record根据架构将记录保存(插入或更新)到数据库

因此,请确保tbl_users表的架构存在。 另外,如Dan U.所述,使用date("Y-m-d H:i:s")代替'Now()'

答案 2 :(得分:0)

dblog 可以让您对查询中的问题有所了解。路径为 admin / reports / dblog