1

为什么mysqli_real_escape_string要询问附加参数?在程序方法中,我们还必须包括连接建立。这背后的逻辑是什么?

4

2 回答 2

2

您正在提供数据库连接链接。这样您就可以同时拥有多个 MySQL 连接。

于 2012-11-27T17:41:51.770 回答
0

在某些情况下,您可能希望打开多个连接并连接到多个 MySQL 数据库。明确说明您要使用的连接链接标识符允许您查询多个 MySQL 数据库而不必担心冲突。

//Open connections to two separate databases. For example: DatabaseOne and DatabaseTwo
$databaseOne = mysqli_connect("example.com", "user", "password", "DatabaseOne");
$databaseTwo = mysqli_connect("example.com", "user", "password", "DatabaseTwo");

//Make variable clean for first connection to DatabaseOne
$var= mysqli_real_escape_string($databaseOne, $var);

//QUERY TABLE FROM DATABASE ONE
$res1 = mysqli_query($databaseOne, "SELECT col FROM tableInDatabaseOne WHERE col = '$var'");
//do something with $res1

//QUERY TABLE FROM DATABASE TWO
$res2 = mysqli_query($databaseTwo, "SELECT col FROM tableInDatabaseTwo");
//do something with $res2
于 2012-11-27T17:53:17.113 回答