4

使用 mysql_error() 函数没有显示错误。msqli_query() 工作正常,但是当我在它旁边添加 mysql_error 时,即使查询无效并且连接错误,我也不会在网页中收到任何信息。

example. mysqli_query($link, $query) or die(mysql_error()); <--- Nothing comes up

链接脚本:

<?php

#SET DATABASE CREDENTIALS
$mysql_host     = 'localhost';
$mysql_username = 'root';
$mysql_password = 'root';
$mysql_db   = 'attendance';
$mysql_error    = 'Error: connection';

//TEST CONNECTION
$link = mysqli_connect( $mysql_host, $mysql_username, $mysql_password, $mysql_db) or die($mysql_error);

if(mysqli_connect_errno())
{

printf("Connection Failed: %s\n", mysqli_connect_error());
exit();

}
?>

查询脚本:

<?php

require('conn.php'); <--- **No Problem**

$query = "SELsECT * FROM `$TBL` WHERE `textFromDate` >= '".mysql_real_escape_string($date1)."' AND `textToDate` <= '".mysql_real_escape_string($date2)."' AND `Scheme`='Paid'";

$resultwholeday = mysqli_query($link, $wholeday) or die(mysql_error()); <--- **might have problem**


?>
4

2 回答 2

9

Use mysqli_error(): http://php.net/manual/en/mysqli.error.php

As far as I know (I may be wrong), every mysql_* function has a relative mysqli_* function. They do not work as substitutes.

EDIT (addressing comment):

According to PHP.net's mysqli_error() docs, it requires one argument to be passed:

string mysqli_error ( mysqli $link )

This mysqli $link that you are passing will be the variable that contains your database connection information. So you create a mysqli connection and save it to $link. Then run some queries. mysqli_error($link) will find the last error that has occurred on $link (or the mysqli connection).

于 2013-03-06T06:00:01.433 回答
2

You want to use mysqli_error, not mysql_error, when you call MySQLi APIs. Same with mysqli_real_escape_string.

于 2013-03-06T06:00:23.800 回答