mysql_query doesnt support multiple queries, a way round this is to use innodb and transactions
________số 8
class MySQLDB
{
private $connection; // The MySQL database connection
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");0
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");1
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");2
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");3
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");4
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");5
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");6
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------0
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------1
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------2
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------3
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------4
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------5
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------6
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------7
this db class/function will accept an array of arrays of querys, it will auto check every line for affected rows in db, if one is 0 it will rollback and return false, else it will commit and return true, the call to the function is simple and is easy to read etc
----------8
Để PHP thực thi các câu lệnh trên chúng ta phải sử dụng hàm mysql_query(). Chức năng này được sử dụng để gửi truy vấn hoặc lệnh đến kết nối MySQL
Ví dụ
Trong chương trước, chúng ta đã tạo một bảng có tên là "Người", có ba cột; . Chúng tôi sẽ sử dụng cùng một bảng trong ví dụ này. Ví dụ sau thêm hai bản ghi mới vào bảng "Người"
____0 mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");Chèn dữ liệu từ biểu mẫu vào cơ sở dữ liệu
Bây giờ chúng ta sẽ tạo một biểu mẫu HTML có thể được sử dụng để thêm các bản ghi mới vào bảng "Người"
Đây là mẫu HTML
____5Khi người dùng nhấp vào nút gửi trong biểu mẫu HTML trong ví dụ trên, dữ liệu biểu mẫu sẽ được gửi đến "chèn. php"
"chèn. php" kết nối với cơ sở dữ liệu và truy xuất các giá trị từ biểu mẫu bằng các biến PHP $_POST
Sau đó, hàm mysql_query() thực thi câu lệnh INSERT INTO và một bản ghi mới sẽ được thêm vào bảng "Persons"