How do I pass arrays, lists and objects into a SQL database using PHP?

  • Thread starter Thread starter Ghost of Tom Joad
  • Start date Start date
G

Ghost of Tom Joad

Guest
I'm trying to figure out the best way to go about doing this, my experience with SQL is pretty limited.
 
<?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.
 
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.
 
Back
Top