-1

I have the following twitter data output in an associative array format in php, how can I insert this data into mysql database table. Kindly suggest any way to do this.

Array (
 [created_at] => Fri, 02 Nov 2012 18:15:57 +0000 
[from_user] => VolksblattNews 
[from_user_id] => 828753642 
[from_user_id_str] => 828753642 
[from_user_name] => Volksblatt News 
[geo] => [id] => 2.6443066310356E+17 
[id_str] => 264430663103557632 
[iso_language_code] => de 
[metadata] => Array ( [result_type] => recent ) 
[profile_image_url] => http://a0.twimg.com/profile_images/2619216207/VB_48x48_reasonably_small_normal.gif 
[profile_image_url_https] => https://si0.twimg.com/profile_images/2619216207/VB_48x48_reasonably_small_normal.gif 
[source] => <a Google</a> => Bundesrat Burkhalter verstärkt Schweizer Beziehungen zu Burma: RANGUN - Didier Burkhalter hat… http://t.co/BF3aX2bY 
[to_user] => 
[to_user_id] => 0 
[to_user_id_str] => 0 [
to_user_name] => )

I got this output from the following program:

 <?php

//a json string

$jsonstring='{


"created_at": "Fri, 02 Nov 2012 18:15:57 +0000", 
   "from_user": "VolksblattNews", 
   "from_user_id": 828753642, 
   "from_user_id_str": "828753642", 
   "from_user_name": "Volksblatt News", 
   "geo": null, 
   "id": 264430663103557632, 
   "id_str": "264430663103557632", 
   "iso_language_code": "de", 
   "metadata": {
    "result_type": "recent"
   }, 
   "profile_image_url": "http://a0.twimg.com/profile_images/2619216207/VB_48x48_reasonably_small_normal.gif", 
   "profile_image_url_https": "https://si0.twimg.com/profile_images/2619216207/VB_48x48_reasonably_small_normal.gif", 
   "source": "&lt;a href=&quot;http://www.google.com/&quot;&gt;Google&lt;/a&gt;", 
   "text": "Bundesrat Burkhalter verst\u00e4rkt Schweizer Beziehungen zu Burma: RANGUN - Didier Burkhalter hat\u2026 http://t.co/BF3aX2bY", 
   "to_user": null, 
   "to_user_id": 0, 
   "to_user_id_str": "0", 
   "to_user_name": null

}';

$arrayvariable=json_decode($jsonstring,true);

print_r ($arrayvariable);

?>

Regards

4
  • please ..format your full array as i have done .... Commented Nov 3, 2012 at 18:05
  • there is a awesome solution which one accepted. stackoverflow.com/questions/1744168/… Commented Nov 3, 2012 at 18:22
  • Do you know how relational databases or the SQL language works? Really hard to tell what you want from an answer here. Does the data have a set schema or do you want to know how to serialize arrays? Commented Nov 3, 2012 at 18:35
  • Have you already your table? If yes show create table plz Commented Nov 3, 2012 at 19:26

1 Answer 1

0

Well depending on the use you could store it in as a json string (in case you want to send it directly to the browser and work with it there) or create a table with all the array values as columns. Then do a insert.

To make a safe the insert or update you have a nice example here using prepared statements and PDO.

http://www.phpeveryday.com/articles/PDO-Insert-and-Update-Statement-Use-Prepared-Statement-P552.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.