如果SQL记录存在,则无法调用php函数

时间:2018-07-23 09:57:45

标签: php mysql sql http-status-code-500

我有此代码:

select 
    a.user_id, 
    a.schedule_date, 
    a.calculated_attendance,
    a.calculation_details,
    s.start_time,
    s.end_time,
    s.breaks
from "Attendance" a, "Schedule" s
where a.user_id = s.user_id
and a.schedule_date = s.schedule_date
and <more filter conditions on Attendance table>

PHP页面应该回显“嘿”,因为不存在这样的记录,但是页面本身甚至根本没有加载,但返回HTTP localhost 500错误,表明localhost无法处理请求。

我知道我做错了事,但我不确定到底是什么。请帮助

2 个答案:

答案 0 :(得分:1)

使用以下代码,因为不建议使用mysql_connect

$connection = mysqli_connect('localhost', 'username', 'password', 'database');
mysqli_query($connection, 'Your query');

答案 1 :(得分:0)

好的,因此删除所有内容并像这样使用

<?php

$mysqli_host = 'localhost';
$mysqli_user = 'root';
$mysqli_password = 'yourPassword';
$mysqli_database = 'yourDatabase';

$mysqli = new mysqli($mysqli_host, $mysqli_user, $mysqli_password, $mysqli_database);

if ($mysqli->connect_errno) {
    die("Connection failed: " . $conn->connect_error);
}

$query = mysqli_query($mysqli, "SELECT person FROM kid WHERE Subs=45");
$result = mysqli_num_rows($query);

if($result > 0) {
    echo("Exist");     
} else {
    echo("Doesn't exist");
}

?>