变量类型由php mysqli返回

时间:2014-03-16 12:54:44

标签: php mysql mysqli variable-types

我在mysql db中有下表,

    CREATE TABLE deadline_tasks(
    user_id REFERENCES user(user_id),
    task_id INT NOT NULL AUTO_INCREMENT,
    deadline DATE NOT NULL,
    min_chunk_length TIME NOT NULL,
    estimated_time TIME NOT NULL,
    location NOT NULL,
    event_name VARCHAR(30) NOT NULL,
    description VARCHAR(30) NOT NULL,
    PRIMARY KEY(task_id)
    FOREIGN KEY (user_id));

我使用下面的代码查询了数据库。

$result_tasks = $mysqli->query("SELECT deadline, min_chunk_length, estimated_duration,  
task_id FROM deadline_tasks WHERE user_id = Get[$Name]")
for($deadline_task_from_db = array(); 
$row = $result_tasks->fetch_assoc();
$deadline_tasks_from_db[] = $row);

我的数组$ deadline_task_from_db中的变量类型是什么?

3 个答案:

答案 0 :(得分:0)

试试:

   $result_tasks = $mysqli->prepare("SELECT deadline, min_chunk_length, estimated_duration,  task_id FROM deadline_tasks WHERE user_id = ? ");
    $result_tasks->bind_param('i', Get[$Name]); // Bind "Get[$Name]" to parameter.
                                     ^^^^^^^^--//i dont know if this true variable. Please check it what you mean by it.
    $result_tasks->execute(); // Execute the prepared query.
    $result_tasks->store_result();
    $result_tasks->bind_result($deadline ,$min_chunk_length ,$estimated_duration,$task_id ); // get variables from result.
    while ($row = $result_tasks->fetch()){
        echo $deadline;
        echo $min_chunk_length;
        .........
      }

答案 1 :(得分:0)

要在php中查看变量的类型,可以使用var_dump http://www.php.net/var_dump

答案 2 :(得分:-1)

使用mysqli_fetch_field(),您可以获取“type”http://www.php.net/manual/en/mysqli-result.fetch-field.php下的类型