mysql_real_query vs mysql_query [关闭]

What is the difference between mysql_real_query and mysql_query? I've made a quick google search but could not find any link that shows the difference between the two.

mysql_real_query() doesn't exist in PHP. However, mysqli_real_query() exists.

According to the official MySQL manual (the C API): http://dev.mysql.com/doc/refman/5.0/en/mysql-real-query.html

mysql_query() cannot be used for statements that contain binary data; you must use mysql_real_query() instead. (Binary data may contain the “\0” character, which mysql_query() interprets as the end of the statement string.) In addition, mysql_real_query() is faster than mysql_query() because it does not call strlen() on the statement string.

About your second issue, the best way to insert multiple records is to create an INSERT query with multiple values:

INSERT INTO table (col1, col2) VALUES (1, 1), (2,2), (3,3)

And so on. This will insert all the new rows in 1 operation, so it should be faster than running 3 queries, one per each row.

PS: You should consider using an extension that supports prepared statements, like MySQLi (note the i) or, even better, PDO. Not only prepared statements are safer (if you use them correctly, they're 100% safe against SQL injections), but also let you do things like those you see in the examples in this page: http://fr2.php.net/manual/en/pdo.prepare.php (you can do that with INSERT queries as well, of course). Ah, and PDO is also object-oriented, which is nice :)

There's no official PHP function mysql_real_query

http://php.net/mysql_real_query

The difference is solely in the C API. One takes a C-style string, the other a buffer and length attribute to allow for NUL bytes. PHP internally uses mysql_real_query.

Insert into table1 (a,b,c) VALUES (1,2,3),(1,2,4),(3,4,5)

This will add three new rows in table1 which should have the columns a, b and c (and possibly others which have default values or can be null).

See https://dev.mysql.com/doc/refman/5.5/en/insert.html