$object = new StdClass; $object->foo = 'bar'; json_encode($object);
while ($row = mysql_fetch_array($result)) {
echo $row[0];
echo $row[1] ;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
}
while ($row = mysql_fetch_object($result)) {
echo $row->user_id;
echo $row->fullname;
}
$dbh = new PDO("mysql:host=localhost;dbname=test", "testuser", "testpass");
$dbh->exec ("CREATE TABLE animal (name CHAR(40), category CHAR(40))");
$dbh->exec ("INSERT INTO animal (name, category)
VALUES
('snake', 'reptile'),
('frog', 'amphibian'),
('tuna', 'fish'),
('racoon', 'mammal')");
$sth = $dbh->query ("SELECT name, category FROM animal");
while ($row = $sth->fetch (PDO::FETCH_OBJ))
printf ("Name: %s, Category: %s\n", $row->name, $row->category);
$dbh = NULL; // closes connection
$sth = $dbh->prepare ("INSERT INTO animal (name, category)
VALUES (:name, :cat)");
$sth->bindValue (":name", "ant");
$sth->bindValue (":cat", "insect");
$sth->execute ();
// or pass values directly to execute() using an array:
$sth->execute (array (":name" => "black widow", ":cat" => "spider"));