PHP / MySQL中的多个数据表? [英] Multiple Data Tables in PHP/MySQL?

查看:183
本文介绍了PHP / MySQL中的多个数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net中,您可以从对数据库的单一调用中检索MULTIPLE数据表。你可以在php中做同样的事情吗?

In asp.net, you can retrieve MULTIPLE datatables from a single call to the database. Can you do the same thing in php?

示例:

$sql ="select * from t1; select * from t2;";
$result = SomeQueryFunc($sql);
print_r($result[0]); // dump results for t1
print_r($result[1]); // dump results for t2

你可以这样做吗?

推荐答案

这被称为多查询。 PHP中的mysql扩展没有任何方法来启用多查询。 mysqli扩展名允许您使用多查询,但只能通过multi_query()方法。请参阅 http://php.net/manual/en/mysqli.multi-query .php

This is called "multi-query." The mysql extension in PHP does not have any means to enable multi-query. The mysqli extension does allow you to use multi-query, but only through the multi_query() method. See http://php.net/manual/en/mysqli.multi-query.php

不建议使用多查询,因为它可以增加SQL注入攻击造成的潜在损害。如果使用多查询,则应该使用严格的代码检查习惯来避免SQL注入漏洞。

Using multi-query is not recommended, because it can increase the potential damage caused by SQL injection attacks. If you use multi-query, you should use rigorous code inspection habits to avoid SQL injection vulnerability.

这篇关于PHP / MySQL中的多个数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆