php - MySQLi returns 0 rows when query is a variable -
my problem simple - utilize mysqli connect script database, when seek execute select statement - returns 0 rows when utilize variable (for ex. $abc) query string...
i utilize function create query:
function get($array) { $select = $array['select']; $from = '`' .$array['from'] . '`'; $fetch = $array['fetch']; $query_text = "select " . $select . " " . $from; if(array_key_exists('where', $array)) { $where = $array['where']; $query_text .= " " . $where; } if(array_key_exists('order', $array)) { $order = $array['order']; if(!empty($order)){ $query_text .= " order " . $order; } } $result = mysqli_query($this->mysqli, $query_text); echo $result->num_rows; } i'm using doing this:
$id = 1; // example. $query = get(array('select' => '*', 'from' => 'something', 'where' => 'id = ' . $id . '', 'fetch' => false); and when ($query = get(...)) shows 0 (because didn't found row), , if in get() function:
function get($array) { [...] $result = mysqli_query($this->mysqli, "select * id = 1"); // it's same query. } then shows 1 - because found 1 row!
these 2 queries identical returns 0 (that 1 variable) , 1 row (that 1 written me). how possible?
php database mysqli
No comments:
Post a Comment