So I have a problem with prepare statement, at all everything works, but it won't work if I bind $table, any suggestions?
execSQL("SELECT id FROM ? WHERE id=?", array('si', $table, $u_id), style::Q_NUM_ROWS)Code:const Q_GET_VALUE = 0; const Q_NUM_ROWS = 1; const Q_AFFECTED_ROWS = 2; function user_exists($u_id, $table) { if ( $this->execSQL("SELECT id FROM ? WHERE id=?", array('si', $table, $u_id), style::Q_NUM_ROWS) != 0 ) return true; return false; } function execSQL($sql, $params, $exec_type) { $stmt = $this->db_connect->prepare($sql) or die ("Failed to prepared the statement!"); if ( !empty($params) ) call_user_func_array(array($stmt, 'bind_param'), $this->refValues($params)); $stmt->execute(); if ( $exec_type == self::Q_GET_VALUE ) { $parameters = array(); $meta = $stmt->result_metadata(); while ( $field = $meta->fetch_field() ) { $parameters[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $this->refValues($parameters)); $stmt->fetch(); $result = $row; } else if( $exec_type == self::Q_NUM_ROWS) { $stmt->store_result(); $result = $stmt->num_rows; } else { $result = $stmt->affected_rows; } $stmt->close(); return $result; } function refValues($arr) { if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+ { $refs = array(); foreach($arr as $key => $value) $refs[$key] = &$arr[$key]; return $refs; } return $arr; }


Reply With Quote

Bookmarks