作为第 5 个参数传递65536
给。mysql_connect
例子:
$conn = mysql_connect('localhost','username','password', true, 65536 /* here! */)
or die("cannot connect");
mysql_select_db('database_name') or die("cannot use database");
mysql_query("
INSERT INTO table1 (field1,field2) VALUES(1,2);
INSERT INTO table2 (field3,field4,field5) VALUES(3,4,5);
DELETE FROM table3 WHERE field6 = 6;
UPDATE table4 SET field7 = 7 WHERE field8 = 8;
INSERT INTO table5
SELECT t6.field11, t6.field12, t7.field13
FROM table6 t6
INNER JOIN table7 t7 ON t7.field9 = t6.field10;
-- etc
");
当您使用 mysql_fetch_* 或 mysql_num_rows 或 mysql_affected_rows 时,只有第一个语句有效。
比如下面的代码,第一条语句是INSERT,不能执行mysql_num_rows和mysql_fetch_*。可以使用 mysql_affected_rows 返回插入的行数。
$conn = mysql_connect('localhost','username','password', true, 65536) or die("cannot connect");
mysql_select_db('database_name') or die("cannot use database");
mysql_query("
INSERT INTO table1 (field1,field2) VALUES(1,2);
SELECT * FROM table2;
");
再比如,下面的代码,第一条语句是SELECT,不能执行mysql_affected_rows。但是您可以执行 mysql_fetch_assoc 来获取第一个 SELECT 语句产生的行的键值对,或者您可以执行 mysql_num_rows 来获取基于第一个 SELECT 语句的行数。
$conn = mysql_connect('localhost','username','password', true, 65536) or die("cannot connect");
mysql_select_db('database_name') or die("cannot use database");
mysql_query("
SELECT * FROM table2;
INSERT INTO table1 (field1,field2) VALUES(1,2);
");