programing

워드프레스 데이터베이스에 쿼리를 삽입하는 방법

easyjava 2023. 4. 4. 23:22
반응형

워드프레스 데이터베이스에 쿼리를 삽입하는 방법

사이트에 이메일 구독이 있으며 Wordpress 데이터베이스에 삽입하여 이메일 목록을 내보내고 싶습니다.ID, 이름, 이메일, 날짜 등 4개의 필드가 작성된 테이블 wp_email_subscription을 이미 작성했습니다.이에 대한 질문은 무엇입니까?사용할 워드프레스 데이터베이스 스크립트가 있습니까?

워드프레스는$wpdb데이터베이스와 상호 작용하기 위한 함수 클래스입니다.

전자 메일 주소를 삽입하려면 다음과 같은 작업을 수행할 수 있습니다.

<?php 

  $wpdb->insert('wp_email_subscription', 
    array(
      'name'          => 'name',
      'address'       => 'name@email.com'
    ),
    array(
      '%s',
      '%s'
    ) 
  ); 

?> 

Wordpress Codex에 대한 자세한 정보.

$wpdb->query("INSERT INTO wp_email_subscription (name, email, date) VALUES ('$name', '$email', '$date')"  );

이것은 테이블에 값을 삽입하는 경우입니다.프리픽스에 $wpdb->email_subscription을 사용할 필요는 없습니다.사용자가 작성한 테이블이기 때문입니다.그렇지 않으면 기본 WordPress 테이블에 값을 삽입할 경우 $wpdb->사용자 등을 실행하는 것이 좋습니다.

할 수 있다

global $wpdb;
$wpdb->insert('wp_email_subscription',array('name'=>$name,'email'=>$email),array('%s','%s'));

자세한 내용은 다음을 참조하십시오.

http://codex.wordpress.org/Class_Reference/wpdb

function insert($array = false)
{
    global $wpdb;
    return $wpdb->insert($wpdb->prefix . 'email_subscription', $array);
}
 global $wpdb

 $wpdb->insert('wp', array(
                        'email' => $_POST['email'],
                        'city'  =>   $_POST['city'],
                        'state' =>$_POST['state'],
                        'phone' => $_POST['phone'],
                       'mobile' => $_POST['mobile'],
                       )
             );
global $wpdb;
$table = $wpdb->prefix.'you_table_name';
$data = array('column1' => 'data one', 'column2' => 123);
$format = array('%s','%d');
$wpdb->insert($table,$data,$format);

여기서 읽을 수 있는 모든 정보

언급URL : https://stackoverflow.com/questions/21964899/how-to-insert-query-in-wordpress-database

반응형