How do I pass arrays, lists and objects into a SQL database using PHP?
|
demo 20 Dec 2008 07:03pm I'm trying to figure out the best way to go about doing this, my experience with SQL is pretty limited. |
Answers
|
demo 20 Dec 2008 07:05pm <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')"); mysql_close($con); ?> Where values are the variables that you want to correspond with the rows in your table. |
|
demo 20 Dec 2008 07:11pm SQL databases normally have 4 data types - character, numeric, date and binary. Arrays and lists are arrays and lists of ... numeric, date or text, so store each element. Objects are ... well, anything. If you can hold the object as a type, store it. (There are too many languages, defining "object" in too many ways, to be more specific.) |
|
demo 20 Dec 2008 07:45pm Use an object oriented db such as Oracle, MySQL only allows for primitive data types (int, varchar, etc,). If you create a module to convert your object into binary and back, then you can place it into a database. |
Related
Submit Answer
You must be logged in to post an answer. Please Login or Register.
Powered by phpMyAnswers.