mysqli对象返回而不是结果


mysqli Object returned instead of result

我在跑步

$this->db->query("SELECT `id` FROM $table WHERE $table.id ='$product_id'");

应该返回92,但它返回下面为什么?

object(CI_DB_mysqli_result)#150 (8) {["conn_id"]=> object(mysqli)#16(18){["affected_rows"]=> int(1)["client_info"]=>字符串(6)"5.5.30"[" client_version "] => int(50530)("connect_errno")=> int (0)[" connect_error "] => NULL("errno")=> int(0)("错误")=>字符串(0)""[" field_count "] => int(1)["host_info"]=>字符串(25)"Localhost通过UNIX socket"("信息")=> NULL("insert_id")=> int(0)("server_info")=>字符串(10)"("5.5.31-cll server_version] => int(50531)("统计")=>字符串(150)正常运行时间:106781线程:14问题:30097132慢查询:13打开:1937675刷新表:1打开表:400查询" ["sqlstate"]=> string(5)"00000"[" protocol_version "] => int(10)("thread_id")=> int (373292)[" warning_count "] => int(0)}["result_id"]=>对象(mysqli_result) # 161(5){["current_field"]=> int(0)("field_count")=> int (1)("长度")=> NULL("num_rows")=> int(1)("类型")=> int (0)}[" result_array "] =>阵列(0){}["result_object"]=>数组(0){}[" custom_result_object "] =>阵列(0){}["current_row"]=> int (0)["num_rows"]=> NULL ["row_data]=> NULL}

返回mysqli_ object。所以试着得到结果就像

$query = $this->db->query("SELECT `id` FROM $table WHERE $table.id ='$product_id'");
$result = $query->result(); 
foreach($result as $row)
{
     echo "Id is ".$row['id']."<br>";
}

使用mysqli_*函数而不是已弃用的mysql_*函数

它返回一个mysqli_result对象,正如手册所说的那样。

要获得实际的id,您需要在对象上调用fetch_assoc()(或类似的)。

if ($result = $this->db->query("SELECT id FROM $table WHERE $table.id ='$product_id'")) {
    /* fetch associative array */
    while ($row = $result->fetch_assoc()) {
        printf ("Fetched ID: %s'n", $row["id"]);
    }
    /* free result set */
    $result->free();
}

基本语句:

$this->db->query("SELECT 'id' FROM $table WHERE $table.id ='$product_id'");

返回一个对象,该对象可用于提取结果集或表,并将其赋值给变量…所以你需要创建一个变量并且结果集赋值给:

$mysqli = new mysqli("localhost","rinonymous","03318987165oo","rinonymous");
if ($mysqli->connect_errno) {
    print_r($mysqli->connect_error);
    exit();
}
$site_title = "Rinonymous";
$page_title = "";
$page_body = "";
#Page Setup
$query_page_info = "select * from pages where id = 1";
foreach ($mysqli->query($query_page_info) as $row) {
    print_r($mysqli->query($query_page_info));
    #query method returns an associate array 
    print_r($row);
    $page_title = $row['title'];
    $page_body = $row['body'];
}