The DB class in the Laravel framework allows us to easily perform database operations, such as common query queries: Db::query (' SELECT * from users '); Larvel also provides a fluent Query builder:db::table (' user ')->where (' id ', ' = ', ' 1 ')->get () similar to the active record in the CI framework; Although there is little difference between the operation and the normal query, it is important to note that the Laravel query results are different from the native queries. Simple set up a contents table test, there is a content field, we query: $content = db::table (' contents ')->where (' id ', ' = ', ' 1 ')->get (); Finally, print out the $content variable to see what the difference is: Array (1)
{
[0]=> object (StdClass) #31 (1) {
["content"]=> string (24) "This is a test ~ ~"}
} From above you can tell that the result of a query is an array of objects, so we must iterate before we get the content value: foreach ($contents as $content)
{echo $content->content;
} In general, Laravel database operations are easy to get started with. |