在php中从mysql中获取多行

时间:2016-11-23 01:47:59

标签: php mysql mysqli

public class TestBalancerServlet {

private static final Logger LOG = Log.getLogger(TestBalancerServlet.class);

public static void main(String[] args) {

    try {
        LOG.info("Initiating the Server startup");

        Server server = new Server(8085);

        // Setup JMX
        MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        server.addEventListener(mbContainer);
        server.addBean(mbContainer);

        // Add loggers MBean to server (will be picked up by MBeanContainer above)
        server.addBean(Log.getLog());

        // 2. Creaing the WebAppContext for the created content
        WebAppContext ctx = new WebAppContext();
        ctx.setResourceBase("src/main/webapp");
        ctx.setContextPath("/jetty-jsp-example");

        ServletHolder jerseyServlet = ctx.addServlet(BalancerServlet.class,"/*");
        DoSFilter2 filter = new DoSFilter2();
        FilterHolder holder = new FilterHolder(filter);
        String name = "DosFilter";
        holder.setName(name);
        holder.setInitParameter("managedAttr", "true");
        holder.setInitParameter("maxRequestsPerSec", "6");
        //_dosFilter.setInitParameter("delayMs", "200");
        holder.setInitParameter("delayMs", "-1");
        ctx.addFilter(holder, "/*", EnumSet.of(DispatcherType.FORWARD));
        ctx.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
        jerseyServlet.setInitOrder(0);
        jerseyServlet.setInitParameter("maxThreads", "1");
        //jerseyServlet.setInitParameter("proxyTo", "http://cnn.com/");
        // give your servlet a name
        jerseyServlet.setName("proxy");
        // parameter is 'balancerMember.NAME.proxyTo'
        jerseyServlet.setInitParameter("balancerMember.proxy.proxyTo", "http://cnn.com/");

        ctx.setAttribute("o:Prg.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*jstl.*\\.jar$");

        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
        server.setHandler(ctx);
        server.start();
        server.join();
        LOG.info("Server has started in 8085 port");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

public static class DoSFilter2 extends DoSFilter
{
    @Override
    public void closeConnection(HttpServletRequest request, HttpServletResponse response, Thread thread)
    {
        try
        {
            response.getWriter().append("DoSFilter: timeout");
            super.closeConnection(request,response,thread);
        }
        catch (Exception e)
        {
            LOG.warn(e);
        }
    }
}

无法在while循环中获取数据。查询工作正常。我试图使用while循环获取每一行的所有属性数据。但是,它不起作用。感谢任何帮助。提前致谢!

1 个答案:

答案 0 :(得分:-2)

改变这个:

$result = mysqli_query($db, $query);
if (!$result) {
    die('Error querying database.');
}

然后验证它是否返回数据

 while ($row = mysqli_fetch_array($result)) {
     var_dump($row);
     ......

我希望这会有所帮助