require_once 'db.php'; $config = [ 'host' => 'localhost', 'username' => 'user', 'password' => 'password', 'database' => 'my_db' ]; $db = new DB($config); // Select data from table $query = "SELECT * FROM users"; $result = $db->run($query); // Display data foreach ($result as $row) { echo $row['name'] . " " . $row['email']; }
require_once 'db.php'; $config = [ 'host' => 'localhost', 'username' => 'user', 'password' => 'password', 'database' => 'my_db' ]; $db = new DB($config); // Insert data into table $query = "INSERT INTO users (name, email) VALUES (?, ?)"; $params = ['John Doe', 'john.doe@example.com']; $result = $db->run($query, $params); if ($result) { echo "Data inserted successfully!"; } else { echo "Error inserting data."; }In this example, we use PHP DB Run to insert new data into the `users` table. We use placeholders (?) in the SQL query and pass in the actual values as an array of parameters. We then check the result of the `run()` method to ensure the data was inserted successfully. Package library: PHP DB Run is part of the broader package library called 'PHP Database Migrations'. This library is used to manage database migrations within PHP projects, allowing you to safely and easily make changes to your database schema over time.