GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing leafphp.dev β Leaf DB | Leaf PHP Leaf DB βInstall the Leaf database module using Leaf CLI or Composer: Leaf CLIComposer bash bash Leaf MVC + DB βLeaf's DB module is great for building simple queries, especially when you are using Leaf as a micro-framework. However, if you are building a full-fledged application using Leaf MVC, you can take advantage of models and schema files, which make it easy to interact with your database. Leaf MVC configures everything for you out of the box, so you just need to define your database schema using the schema files and create models to represent your database tables. You can then use the models to perform CRUD operations on your database without writing any SQL queries. 01 / StructureSchema filesDefine tables, columns, relationships, and seed data in one readable file.Create your schema β02 / RecordsModelsGive your data a clean, object-oriented API for everyday application logic.Explore models β03 / QueriesQuery builderDrop closer to SQL when you need precise control without losing readability.Open the builder β Connecting to a database βThe first step to using a database is to create a connection. It's like opening a door to the database, allowing you to interact with it. Here's how you can connect to a database using Leaf: php The MySQLPostgreSQLSQLite php php php Leaf DB will not connect to your database until you run a query. This means that you can pass in your database connection at the beginning of your application and only connect when you need to run a query which is a great way to save resources. Multi-DB Connections NEW βSome applications may need to connect to multiple databases for things like queues and logs, and Leaf DB allows you to keep multiple connections open and query them independently. Here's how you can connect to multiple databases: php The php If no connection name is provided, Leaf DB will use the default connection. Writing simple queries βOnce you've connected to a database, you can start writing queries to interact with it. Queries are the commands you run on your database to get, insert, update or delete data. Leaf DB provides a simple way to run queries using the query builder, but also allows you to run raw SQL queries. We can run queries using the php The php Note that Running queries βThere are different kinds of database commands: some give you results (like data) and some donβt. Leaf Db makes it easy to handle both types without any hassle. You can use php If you want to run a query that returns data, you can use the php This will return an array of all the users in the database that match the query. If you only want to get one result, you can use the php This will return the matched user as an object. There may be times when you want to get a single value from a query that returns multiple rows. In such cases, you can use the php |
| You are visitor 01402503 β GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ600. No cookies required. |