PHP.mk документација

PDO_PGSQL DSN

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

ref.pdo-sqlite.connection.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека ref.pdo-sqlite.connection.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
PDO_PGSQL DSN

Референца за `ref.pdo-sqlite.connection.php` со подобрена типографија и навигација.

ref.pdo-sqlite.connection.php

PDO_PGSQL DSN

(PHP 5 >= 5.1.0, PHP 7, PECL PDO_SQLITE >= 0.2.0)

PDO_PGSQL DSN(PHP 5 >= 5.1.0, PHP 7, PECL PDO_SQLITE >= 0.2.0)

= NULL

Поврзување со SQLite бази на податоци

Името на изворот на податоци (DSN) за PDO_SQLITE се состои од следниве елементи:

DSN префикс sqlite:.

  • DSN префикс (SQLite 3)

  • За пристап до база на податоци на диск, апсолутната патека мора да се додаде на DSN префиксот. :memory: За креирање на база на податоци во меморија,

  • мора да се додаде на DSN префиксот.

Примери

Ако DSN се состои само од DSN префиксот, се користи привремена база на податоци, која се брише кога врската ќе се затвори.

Пример #1 PDO_SQLITE DSN примери

sqlite:/opt/databases/mydb.sq3
sqlite::memory:
sqlite:

Белешки од корисници 5 белешки

Следниве примери покажуваат PDO_SQLITE DSN за поврзување со SQLite бази на податоци:
пред 14 години
In memory sqlite has some limitations. The memory space could be the request, the session, but no way seems documented to share a base in memory among users.

For a request, open your base with the code
$pdo = new PDO( 'sqlite::memory:');
and your base will disapear on next request.

For session persistency
<?php
$pdo = new PDO(
    'sqlite::memory:',
    null,
    null,
    array(PDO::ATTR_PERSISTENT => true)
);
?>
frederic dot glorieux at diple dot net
пред 17 години
It seems that the directory that contains your sqlite database must be writeable by the web server. Making just the file writeable won't work.
Fatmoon
пред 10 години
Some notes that may or may not be obvious..

In general, when using an in-memory (:memory:) database from within a PHP script (such as code in an index.php file for a web server), the memory used for the database exists only as long as the PHP code is running. Usually, this is only as long as it takes to deliver output back to the web server trying to serve the web page to the client. There is no way (that I know of, please correct me if I'm wrong) to share an in-memory database across different web connections, including different multiple connections from the same client. *This does include "persistent" connections.* The reason for this is because in-memory databases *are* in-memory databases, and the memory allocated by the web server/PHP processor is allocated and released "on the fly". Otherwise, web servers which serve thousands of web pages would quickly consume all available memory (and swap space), and come to a grinding halt when the system no longer has available memory to handle more requests.

If you need to share data across sessions, connections, or scripts, you'll need to use a database file in a folder/directory which is *writable* by the web server/PHP extension, as SQLite3 may use some temporary files while working with the database. (In my Debian Linux installation, this is the "www-data" psuedo-user/group.) (You can consult the SQLite3 documentation if you wish to know what temporary files it uses; They are well-documented.)

In short, it is a _logical_error_ to think of in-memory databases as anything other than very short-term temporary databases. They may be useful if you only wish to work with a subset of a larger database within *a single web page, AND only while the PHP script is generating the web page*. That is, you cannot use in-memory databases to store a user's "shopping cart", for example, because a shopping cart would still need to load many different web pages, invoking many different PHP scripts, each with their own memory space. Likewise, once PHP has generated the output of the web page for the server to send on to the client, PHP is no longer "part of the picture", and any memory it had allocated may be freed for other uses--including your in-memory database.

This is not a limitation of the web server, PHP, or SQLite, but of how operating systems work in general to share limited resources (such as memory) between processes/users/connections/et cetera.
rick
19 години пред
Don't forget "extension=php_pdo_sqlite.dll" has to be enabled in php.ini (if you use xampp is will be disabled by default) .
FST777
пред 17 години
@ Fatmoon
That is correct. SQLite sometimes uses additional files in the same folder while writing to the DB. These files can sometimes be seen and usually contain the name of your DB and the word 'journal' in their filename.
Security wise, it might be a good idea to store the SQLite databases in a seperate folder to shield the rest from user www.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.