Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-到数据库的多个连接_Php_Connection - Fatal编程技术网

php-到数据库的多个连接

php-到数据库的多个连接,php,connection,Php,Connection,我有一个登录页面,可以获取用户名和pwd,并在将它们传递给DB之前对它们进行清理 这是通过一个函数完成的: function make_safe($text) { open_db_connection(); //this opens another connection! if(get_magic_quotes_gpc()) { $text = stripslashes($text); } $text = mysql_real_escape_string($text);

我有一个登录页面,可以获取用户名和pwd,并在将它们传递给DB之前对它们进行清理

这是通过一个函数完成的:

function make_safe($text) {
  open_db_connection(); //this opens another connection!

  if(get_magic_quotes_gpc()) {
    $text = stripslashes($text);
  }
  $text = mysql_real_escape_string($text);
  return $text;
}
这个函数是从一个已经有打开连接的脚本调用的,但我仍然发现我必须在“make_uuuuusafe()”中打开另一个连接才能工作(否则我会得到一个“警告:mysql_ureal_uescape_ustring()[function.mysql real escape string]:拒绝用户访问blablabla@localhost……”

我想知道:

1) 当我打电话给make_safe时,我已经有了一个开放的连接-为什么这还不够

2) 打开多个连接有什么问题

谢谢,
patrick

我认为您可能需要为mysql\u real\u escape\u string提供第二个参数。

我不是php专家,但
make\u safe
与数据库的多个连接的发生无关,是吗?好的:mysql\u real\u escape\u string()需要一个连接才能运行。默认情况下,它使用最近打开的连接。因此,是的,打开多个连接可能会产生影响。第二个参数是(resource$LinkId标识符),默认情况下,它将使用最后一个打开的连接,但您可以指定较旧的连接。