创建一个包含会话名称的php表

时间:2016-03-18 07:55:52

标签: php mysql windows session

我无法在任何地方找到答案。但很简单,我有一个创建表和一个保存的会话。我需要该会话作为表名。这显示如下。我一直在努力,并试图找到答案。

下面是create msql表。会话是$ id,以下是我到目前为止所尝试过的。

@Autowired

这是上下文中的页面(已更新)



import java.util.Arrays;

import javax.jws.WebService;

import org.apache.cxf.Bus;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@EnableAutoConfiguration
@ImportResource({ "classpath:META-INF/cxf/cxf.xml" })
public class Application extends SpringBootServletInitializer {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    private MyInterceptor myInterceptor;

    @Autowired
    private HelloWorldImpl helloWorldImpl;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    // Replaces the need for web.xml
    @Bean
    public ServletRegistrationBean servletRegistrationBean(ApplicationContext context) {
        return new ServletRegistrationBean(new CXFServlet(), "/api/*");
    }

    // Replaces cxf-servlet.xml
    @Bean
    // <jaxws:endpoint id="helloWorld" implementor="demo.spring.service.HelloWorldImpl" address="/HelloWorld"/>
    public EndpointImpl helloService() {
        Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
        EndpointImpl endpoint = new EndpointImpl(bus, helloWorldImpl);

        // Set interceptors here
        endpoint.setInInterceptors(Arrays.asList(myInterceptor));

        endpoint.publish("/hello");
        return endpoint;
    }


    // Used when deploying to a standalone servlet container, i.e. tomcat
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    // Web service endpoint
    @WebService(endpointInterface = "demo.spring.service.HelloWorld")
    //@InInterceptors not defined here
    public static class HelloWorldImpl {

    }

    public static class MyInterceptor extends LoggingInInterceptor {
      // @Autowired works here
    }

}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您可以使用session IDsession_id()):

$id = session_id();
if (!empty($id) {
    $sql = "CREATE TABLE " . $id . " (
            id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
            firstname VARCHAR(30) NOT NULL,
            lastname VARCHAR(30) NOT NULL,
            email VARCHAR(50),
            reg_date TIMESTAMP
    )";
}

实际上为什么你需要它作为桌子的名字吗?

答案 1 :(得分:0)

尝试使用此查询

  $sql = "CREATE TABLE '. $id .' (
   id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    email VARCHAR(50),
     reg_date TIMESTAMP
   ) ";