downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SQLite3::prepare> <SQLite3::loadExtension
[edit] Last updated: Fri, 23 Mar 2012

view this page in

SQLite3::open

(PHP 5 >= 5.3.0)

SQLite3::openBir SQLite veritabanını açar

Açıklama

public bool SQLite3::open ( string $dosya [, int $seçenekler = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE [, string $anahtar ]] )

dosya ile belirtilen SQLite 3 veritabanını açar. Veritabanı şifreli ise belirtilen anahtar ile şifresi çözülmeye çalışılır.

Değiştirgeler

dosya

SQLite veritabanını içeren dosyanın yolu.

seçenekler

SQLite veritabanının nasıl açılacağını belirleyen seçimlik seçenekler. Öntanımlı olarak, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE kullanılır.

  • SQLITE3_OPEN_READONLY: Veritabanı okumak için açılır.

  • SQLITE3_OPEN_READWRITE: Veritabanı hem okumak hem de yazmak için açılır.

  • SQLITE3_OPEN_CREATE: Veritabanı yoksa oluşturulur.

anahtar

SQLite veritabanını şifrelemek/şifresini çözmek için kullanılan şifreleme anahtarı.

Dönen Değerler

Veritabanı açılabilirse TRUE yoksa FALSE döner.

Örnekler

Örnek 1 - SQLite3::open() örneği

<?php
$db 
= new SQLite3('mysqlitedb.db');

$db->exec('CREATE TABLE foo (bar STRING)');
$db->exec("INSERT INTO foo (bar) VALUES ('Bu bir denemedir')");

$result $db->query('SELECT bar FROM foo');
var_dump($result->fetchArray());
?>



SQLite3::prepare> <SQLite3::loadExtension
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes SQLite3::open
jjchailloux at yahoo dot com 06-Jul-2010 01:09
PHP Fatal error:  Class 'SQLite3' not found ...

you are probably running an old version of PHP

PHP 5.2 does not know about SQLite3; only SQLite (v2)

install PHP 5.3
http://www.macupdate.com/info.php/id/7294/php on Mac OS
cr at caltel dot com 05-May-2010 08:49
If you are getting:
  PHP Fatal error:  Class 'SQLite3' not found ...

Try:
  $db = new PDO('sqlite:mysqlitedb.db');

I assume there must be a "better" way, but I don't know it.
kbrobst at surveyresearchpartners dot com 07-Mar-2010 05:54
If you are trying to use the open() method to open multiple database files within the same SQLite3 object (which I could not get to work), here is an alternative way to do so using special SQLite3 syntax additions to the SQL language.  This took some investigation on my part, so hopefully the solution I found will help you too.

These are the nice features within SQLite3 that are leveraged:
* The create statement query for a table is stored within a table called "sqlite_master" within the parent database file.
* SQLite3 supports the "insert into...select * from" SQL syntax for doing bulkload-speed inserts into a table - but what if the source and target tables are in separate database files?
* SQLite3 has an "attach [filename] as [reference database name]" which will allow multiple database files to be opened and accessible to the same SQLite3 object.

Assume you have a table called "my_template" in the SQLite3 database file "source.db".  You want to make a copy of this table into the database file "target.db" and call the table "working_table".

<?php
//attach the source database file to the bulkload connection object;
$bulkload_connection = new SQLite3("c:/sqlite3_database_files/source.db");

//retrieve the create statement query for the source table;
$sourcetbl_create_statement = $bulkload_connection->querySingle("select sql from sqlite_master where type='table' and name='my_template'");
if (
$sourcetbl_create_statement===false) exit($bulkload_connection->lastErrorMsg());

//build the create statement query for the target table;
$targettbl_create_statement = str_replace('CREATE TABLE my_template', 'CREATE TABLE bulkload.working_table', $sourcetbl_create_statement);

//attach the target database file to the bulkload connection object - and reference it as the database called [bulkload];
$result=$bulkload_connection->exec("attach 'c:/sqlite3_database_files/target.db' as bulkload");
if (
$result===false) exit($bulkload_connection->lastErrorMsg());

//issue the query to create the target table within the target database file;
$result=$bulkload_connection->exec($targettbl_create_statement);
if (
$result===false) exit($bulkload_connection->lastErrorMsg());

//copy the rows from the source table to the target table as quickly as possible;
$result=$bulkload_connection->exec("insert into bulkload.working_table select * from my_template");
if (
$result===false) exit($bulkload_connection->lastErrorMsg());

//release the OS file locks on the attached database files;
$bulkload_connection->close();
unset(
$bulkload_connection);
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites