Home Backend Development PHP Tutorial PHP database framework Medoo1.6 installation tutorial

PHP database framework Medoo1.6 installation tutorial

May 04, 2020 am 09:34 AM
medoo php

Start

Using Medoo is very simple!

Medoo1.2 does not support PHP5.4 or below. If you are using it before 1.2 Version, please select the menu Chinese Document (<1.2)

Requirements

1, PHP>=5.4, must support PDO

2, support MySQL, MSSQL, SQLite and other databases.

3. Make sure that the xxx data extension of php_pdo_xxx (xxx = database type) has been correctly installed and enabled.

4. You need to know some SQL knowledge.

PHP PDO extension list

MySQL, MariaDB -> php_pdo_mysql

MSSQL (Windows) -> php_pdo_sqlsrv

MSSQL (Liunx /UNIX) -> php_pdo_dblib / php_pdo_sqlsrv

Oracle -> php_pdo_oci

Oracle version 8 -> php_pdo_oci8

SQLite -> php_pdo_sqlite

PostgreSQL -> php_pdo_pgsql

Sybase -> php_pdo_dblib

PHP PDO installation

medoo requires PHP to support PDO extensions, please install the relevant extensions Continue the following operations

// 打开php.ini找到你想要的相应扩展,去掉前面的;号即可
// 将
;extension=php_pdo_mysql.dll
// 修改成
extension=php_pdo_mysql.dll
// 保存,重启你的PHP或者服务器
//如果PDO安装成功,你可以通过phpinfo()查看到它.
Copy after login

If you install through the terminal (linux) command line, the system will automatically install and configure the corresponding extension

$ sudo apt-get install php5-mysql
Copy after login

Use PHP Composer to install

If you install it through the dependency extension that comes with PHP, you can use the following command, or you can modify it according to your own needs.

$ composer require catfan/Medoo
Copy after login

Source file installation

This is the simplest method, download the medoo source file, put it in your PHP development directory, and load it

require  &#39;medoo.php&#39;;
Copy after login

Medoo configuration

Here provides three database connection demonstrations.

// If you installed via composer, just use this code to requrie autoloader on the top of your projects.
require &#39;vendor/autoload.php&#39;;
 
// Using Medoo namespace
use Medoo\Medoo;
 
$database = new Medoo([
    // required
    &#39;database_type&#39; => &#39;mysql&#39;,
    &#39;database_name&#39; => &#39;name&#39;,
    &#39;server&#39; => &#39;localhost&#39;,
    &#39;username&#39; => &#39;your_username&#39;,
    &#39;password&#39; => &#39;your_password&#39;,
 
    // [optional]
    &#39;charset&#39; => &#39;utf8&#39;,
    &#39;port&#39; => 3306,
 
    // [optional] Table prefix
    &#39;prefix&#39; => &#39;PREFIX_&#39;,
 
    // [optional] Enable logging (Logging is disabled by default for better performance)
    &#39;logging&#39; => true,
 
    // [optional] MySQL socket (shouldn&#39;t be used with server and port)
    &#39;socket&#39; => &#39;/tmp/mysql.sock&#39;,
 
    // [optional] driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
    &#39;option&#39; => [
        PDO::ATTR_CASE => PDO::CASE_NATURAL
    ],
 
    // [optional] Medoo will execute those commands after connected to the database for initialization
    &#39;command&#39; => [
        &#39;SET SQL_MODE=ANSI_QUOTES&#39;
    ]
]);
 
$database->insert("account", [
    "user_name" => "foo",
    "email" => "foo@bar.com"
]);
Copy after login

Customized DSN link

Missing You can also use custom DSN connections for databases that Medoo does not support, especially for new databases where the DSN parameters are special, or if you want to add more DSN parameter values ​​to the connection.

Connection format.

{driver}:{key}={value};{key}={value}
Copy after login
$database = new Medoo([
    // Started using customized DSN connection
    &#39;dsn&#39; => [
        // The PDO driver name for DSN driver parameter
        &#39;driver&#39; => &#39;mydb&#39;,
        // The parameters with key and value for DSN
        &#39;server&#39; => &#39;12.23.34.45&#39;,
        &#39;port&#39; => &#39;8886&#39;
    ],
    // [optional] Medoo will have different handle method according to different database type
    &#39;database_type&#39; => &#39;mysql&#39;,
 
    &#39;username&#39; => &#39;your_username&#39;,
    &#39;password&#39; => &#39;your_password&#39;
]);
 
// The final DSN connection string will be generated like this
mydb:server=12.23.34.45;port=8886
Copy after login

Connect to SQLite

If you want to use Medoo to connect to your MSSQL database, you need to install the relevant extension: Windows installation pdo_sqlsrv , Linux/UNIX install pdo_dblib. The pdo_mssql extension has been abandoned by PHP and is not recommended.

$database = new Medoo([
    &#39;database_type&#39; => &#39;mysql&#39;,
    &#39;database_name&#39; => &#39;name&#39;,
    &#39;server&#39; => &#39;localhost&#39;,
    &#39;username&#39; => &#39;your_username&#39;,
    &#39;password&#39; => &#39;your_password&#39;,
 
    // [optional] The application name
    &#39;appname&#39; => &#39;test&#39;,
 
    // [optional] If you want to force Medoo to use dblib driver for connecting MSSQL database
    &#39;driver&#39; => &#39;dblib&#39;
]);
Copy after login

Now Medoo can use sqlsrv to drive MSSQL. For details, see Microsoft official documentation https://docs.microsoft.com/en -us/sql/connect/php/connection-options?view=sql-server-2017.

$database = new Medoo([
    &#39;database_type&#39; => &#39;mysql&#39;,
    &#39;database_name&#39; => &#39;name&#39;,
    &#39;server&#39; => &#39;localhost&#39;,
    &#39;username&#39; => &#39;your_username&#39;,
    &#39;password&#39; => &#39;your_password&#39;,
 
    // [optional] MSSQL connection options
    &#39;application_intent&#39; => &#39;ReadOnly&#39;,
    &#39;attach_db_file_name&#39; => &#39;./database.sql&#39;,
    &#39;authentication&#39; => &#39;SqlPassword&#39;,
    &#39;column_encryption&#39; => &#39;Enabled&#39;,
    &#39;connection_pooling&#39; => 1,
    &#39;encrypt&#39; => 1,
    &#39;failover_partner&#39; => &#39;MultiSubnetFailover&#39;,
    &#39;key_store_authentication&#39; => &#39;KeyVaultPassword&#39;,
    &#39;key_store_principal_id&#39; => &#39;AzureName&#39;,
    &#39;key_store_secret&#39; => &#39;AzurePass&#39;,
    &#39;login_timeout&#39; => &#39;20&#39;,
    &#39;multiple_active_result_sets&#39; => 1,
    &#39;multi_subnet_failover&#39; => &#39;Yes&#39;,
    &#39;scrollable&#39; => &#39;buffered&#39;,
    &#39;trace_file&#39; => &#39;./path&#39;,
    &#39;trace_on&#39; => 1,
    &#39;transaction_isolation&#39; => PDO::SQLSRV_TXN_SNAPSHOT,
    &#39;transparent_network_ip_resolution&#39; => &#39;Enabled&#39;,
    &#39;trust_server_certificate&#39; => 1,
    &#39;wsid&#39; => &#39;Computer1&#39;
]);
Copy after login

Connect to SQLite

$database = new medoo([
    &#39;database_type&#39; => &#39;sqlite&#39;,
    &#39;database_file&#39; => &#39;my/database/path/database.db&#39;
]);
 
$database->insert("account", [
    "user_name" => "foo",
    "email" => "foo@bar.com"
]);
Copy after login

The above is the detailed content of PHP database framework Medoo1.6 installation tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles