在我的代码的评论部分,我试图通过合计$ totalmin和$ totalhours来获得总工作时间,但是我得到了错误。 我得到了:
Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\xampp\htdocs\app\login\gr\ewh.php on line 66 ($result = mysqli_query($conn,$sql);)
Warning: mysqli_error() expects parameter 1 to be mysqli, object given in C:\xampp\htdocs\app\login\gr\ewh.php on line 68 (printf("Error: %s\n", mysqli_error($conn));)
我做错了什么?是语法吗?数据库连接或其他东西..
try {
$conn = new PDO('mysql:host=localhost;dbname=jj', 'root', 'awd');
$conn->exec("set names utf8");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$num_rows = $conn->query('SELECT COUNT(*) FROM employees')->fetchColumn();
$stmt = $conn->prepare("SELECT employees.name,employees.division FROM employees WHERE employees.status='Employed' A LIMIT :start,:end");
$stmt->bindParam(':start', $pages->limit_start, PDO::PARAM_INT);
$stmt->bindParam(':end', $pages->limit_end, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll();
$ewhtable = "<table class='sortable'><th>Employee Name</th></tr>\n";
foreach($result as $row) {
$years=explode("/", $row[2]);
$years[2]=intval(date ('Y')) - $years[2];
/*
$sql="SELECT WorkingHours FROM WOrkHours WHERE AFNumber=$row[0]";
$result = mysqli_query($conn,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
while($row = mysqli_fetch_array($result)){
$temp = explode(":", $row['WorkingHours']);
$hoursworked+=intval($temp[0]);
$minsworked+=intval($temp[1]);
$totalworkedhours=$hoursworked+($minsworked/60);
$totalmin= $totalworkedhours % 60;
$totalhours=$totalworkedhours-$totalmin;
}
*/
答案 0 :(得分:4)
您似乎正在从PDO切换到MySQLi .. ..stick到PDO,您的问题将不存在。
$conn
是您的PDO数据库句柄,随后将无法传递给mysqli_ *函数。