php sqlite3 fetch,PHP sqlite_fetch_array 用法 手册 | 示例代码

[Editor's note: to get short column names there's an undocumented PRAGMA setting. You can exec "PRAGMA short_column_names = ON" to force that behavior.]

I noticed that if you use Joins in SQL queries, the field name is messed up with the dot!

for example if you have this query:

SELECT n.*, m.nickname FROM news AS n, members AS m WHERE n.memberID = m.id;

now if you want to print_r the results returned using SQLITE_ASSOC type, the result array is like this :

array

(

[n.memberID] => 2

[n.title] => test title

[m.nickname] => NeverMind

[tablename.fieldname] => value

)

and I think it looks horriable to use the variable ,for example, $news['m.nickname'] I just don't like it!

so I've made a small function that will remove the table name (or its Alias) and will return the array after its index is cleaned

{

foreach ($arrayas$key=>$value) {//if you want to keep the old element with its key remove the following lineunset($array[$key]);