if ($ mysqli -> connect_errno) {& nbsp; Echo "Không thể kết nối với MySQL:". $ mysqli -> Connect_error; & nbsp; lối ra(); }
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// thực hiện truy vấn, kiểm tra lỗi (! $ Mysqli -> truy vấn ("chèn vào giá trị của người (firstName) ('glenn')")) {& nbsp; echo ("Mô tả lỗi:". $ mysqli -> lỗi); }
if (!$mysqli -> query("INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
echo("Error description: " . $mysqli -> error);
}
Nhìn vào ví dụ về phong cách thủ tục ở phía dưới.
Hàm lỗi / mysqli_error () trả về mô tả lỗi cuối cùng cho cuộc gọi chức năng gần đây nhất, nếu có.
if ($ mysqli -> connect_errno) {& nbsp; Echo "Không thể kết nối với MySQL:". $ mysqli -> Connect_error; & nbsp; lối ra(); }
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// thực hiện truy vấn, kiểm tra lỗi (! $ Mysqli -> truy vấn ("chèn vào giá trị của người (firstName) ('glenn')")) {& nbsp; echo ("Mô tả lỗi:". $ mysqli -> lỗi); }
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')"))
{
echo("Error description: " . mysqli_error($con));
}
(Php 4, Php 5)
mysql_error - Trả về văn bản của thông báo lỗi từ hoạt động MySQL trước đó — Returns the text of the error message from previous MySQL operation
Sự mô tả
mysql_error (tài nguyên $link_identifier
= null): Chuỗi(resource $link_identifier
= NULL): string
Thông số
link_identifier
Kết nối MySQL. Nếu định danh liên kết không được chỉ định, liên kết cuối cùng được mở bởi mysql_connect () được giả định. Nếu không tìm thấy liên kết như vậy, nó sẽ cố gắng tạo một liên kết như thể mysql_connect () đã được gọi mà không có đối số. Nếu không tìm thấy kết nối hoặc thiết lập, lỗi cấp E_WARNING
được tạo ra.mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an
E_WARNING
level error is generated.
Trả về giá trị
Trả về văn bản lỗi từ hàm MySQL cuối cùng hoặc ''
(chuỗi trống) nếu không xảy ra lỗi.
Ví dụ
Ví dụ #1 mysql_error () ví dụmysql_error() example
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:
1049: Unknown database 'nonexistentdb'
1146: Table 'kossu.nonexistenttable' doesn't exist
Xem thêm
- mysql_errno () - Trả về giá trị số của thông báo lỗi từ thao tác MySQL trước đó
- »& NBSP; Mã lỗi MySQL
Aleczapka _at) gmx dot net ¶ ¶
18 năm trước
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
Note. There is a bug in either documentation about error_reporting() or in mysql_error() function cause manual for mysql_error(), says: "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.
Florian Sidler ¶ ¶
12 năm trước
Be aware that if you are using multiple MySQL connections you MUST support the link identifier to the mysql_error() function. Otherwise your error message will be blank.
$link_identifier
0
Lâu đài Pendragon ¶
13 năm trước
$link_identifier
2
$link_identifier
3
$link_identifier
4
$link_identifier
5 l dot poot tại twing dot nl ¶ ¶
16 năm trước
$link_identifier
6
$link_identifier
7
$link_identifier
8
$link_identifier
9
link_identifier
0
link_identifier
1
link_identifier
2
link_identifier
3
link_identifier
4Ẩn danh ¶ ¶
17 năm trước
link_identifier
5
link_identifier
6
link_identifier
7
link_identifier
8
link_identifier
9
E_WARNING
0
E_WARNING
1
Olaf tại Amen-Online Dot de ¶ ¶
18 năm trước
E_WARNING
3
E_WARNING
4
Ẩn danh ¶ ¶
17 năm trước
E_WARNING
6
E_WARNING
7
E_WARNING
8
Olaf tại Amen-Online Dot de ¶ ¶
21 năm trước
''
0
''
1
''
2
Gianluigi_zanettini-megalab.it ¶ ¶
15 năm trước
''
4
''
5
''
6
''
7
''
8
''
9
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
0
Scott tại Rocketpack Dot Net ¶
15 năm trước
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
2
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
3
Scott tại Rocketpack Dot Net ¶
21 năm trước
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
5
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
6
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
7
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
8
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
9
Olaf tại Amen-Online Dot de ¶ ¶
21 năm trước
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
1
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
2
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
3
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
4
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
5
Gianluigi_zanettini-megalab.it ¶ ¶
15 năm trước
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
6
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
7
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
8
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use $php_errormsg. This Warning will be stored there. You need to have track_errors set to true in your php.ini.
9
Note. There is a bug in either documentation about error_reporting() or in mysql_error() function cause manual for mysql_error(), says: "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.
0
Note. There is a bug in either documentation about error_reporting() or in mysql_error() function cause manual for mysql_error(), says: "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.
1
Note. There is a bug in either documentation about error_reporting() or in mysql_error() function cause manual for mysql_error(), says: "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.
2
PDO chỉ đơn giản là đặt mã lỗi để bạn kiểm tra bằng các phương thức PDO :: ErrorCode () và PDO :: ErrorInfo () trên cả đối tượng câu lệnh và cơ sở dữ liệu;Nếu lỗi xuất phát từ một cuộc gọi trên đối tượng câu lệnh, bạn sẽ gọi pDostatement :: ErrorCode () hoặc pDostatement :: ErrorInfo () phương thức trên đối tượng đó.PDO::errorCode() and PDO::errorInfo() methods on both the statement and database objects; if the error resulted from a call on a statement object, you would invoke the PDOStatement::errorCode() or PDOStatement::errorInfo() method on that object.
Chúng ta có thể thực hiện truy vấn đối với cơ sở dữ liệu bằng phương thức php mysqli_query ().Cú pháp: Chúng ta có thể sử dụng phương thức mysqli_Query () theo hai cách: kiểu hướng đối tượng.Phong cách thủ tục.using the PHP mysqli_query() method. Syntax: We can use the mysqli_query( ) method in two ways: Object-oriented style. Procedural style.
Hàm mysqli_error () trả về mô tả về lỗi xảy ra trong cuộc gọi hàm mySQLI cuối cùng.mysqli_error() function returns the description of the error occurred during the last MySQLi function call.
Với PHP, bạn có thể kết nối và thao tác cơ sở dữ liệu.MySQL là hệ thống cơ sở dữ liệu phổ biến nhất được sử dụng với PHP.MySQL is the most popular database system used with PHP.