PHP:SQLite-Manual中存取函數轉貼

PHP:SQLite-Manual中存取函數轉貼

PHP:SQLite-Manual中存取函數轉貼

 

資料來源:http://php.net/manual/en/book.sqlite.php

 

  • sqlite_array_query — Execute a query against a given database and returns an array(執行查詢對一個給定的數據庫,並返回一個數組)
  • sqlite_busy_timeout — Set busy timeout duration, or disable busy handlers(忙碌的設置超時時間,或禁用忙處理)
  • sqlite_changes — Returns the number of rows that were changed by the most recent SQL statement(返回由最近的SQL語句更改的行數)
  • sqlite_close — Closes an open SQLite database(關閉打開的SQLite數據庫)
  • sqlite_column — Fetches a column from the current row of a result set(取從結果集的當前行的列)
  • sqlite_create_aggregate — Register an aggregating UDF for use in SQL statements(註冊一個UDF聚集在SQL語句中使用)
  • sqlite_create_function — Registers a “regular” User Defined Function for use in SQL statements(註冊一個“普通”用戶定義的函數在SQL語句中使用)
  • sqlite_current — Fetches the current row from a result set as an array(從結果集作為數組獲取當前行)
  • sqlite_error_string — Returns the textual description of an error code(返回的錯誤代碼的文本描述)
  • sqlite_escape_string — Escapes a string for use as a query parameter(轉義一個字符串用作查詢參數)
  • sqlite_exec — Executes a result-less query against a given database(執行針對給定的數據庫的結果無查詢)
  • sqlite_factory — Opens an SQLite database and returns an SQLiteDatabase object(打開一個SQLite數據庫,並返回一個SQLiteDatabase對象)
  • sqlite_fetch_all — Fetches all rows from a result set as an array of arrays(獲取所有行的結果集作為一個數組的數組)
  • sqlite_fetch_array — Fetches the next row from a result set as an array(從結果集作為數組讀取下一行)
  • sqlite_fetch_column_types — Return an array of column types from a particular table(返回的列類型的數組,從一個特定的表)
  • sqlite_fetch_object — Fetches the next row from a result set as an object(從結果集作為一個對象讀取下一行)
  • sqlite_fetch_single — Fetches the first column of a result set as a string(取指結果的第一列設置為一個字符串)
  • sqlite_fetch_string — Alias of sqlite_fetch_single(sqlite_fetch_single的別名)
  • sqlite_field_name — Returns the name of a particular field(返回一個特定字段的名稱)
  • sqlite_has_more — Finds whether or not more rows are available(找到更多的行是否是可用的)
  • sqlite_has_prev — Returns whether or not a previous row is available(返回先前的行是否是可用的)
  • sqlite_key — Returns the current row index(返回當前行的索引)
  • sqlite_last_error — Returns the error code of the last error for a database(返回最後一個錯誤的錯誤代碼數據庫)
  • sqlite_last_insert_rowid — Returns the rowid of the most recently inserted row(返回最近插入的行的ROWID)
  • sqlite_libencoding — Returns the encoding of the linked SQLite library(返回鏈接的SQLite庫的編碼)
  • sqlite_libversion — Returns the version of the linked SQLite library(返回鏈接的SQLite庫的版本)
  • sqlite_next — Seek to the next row number(求到下一行號)
  • sqlite_num_fields — Returns the number of fields in a result set(返回的結果集的字段數)
  • sqlite_num_rows — Returns the number of rows in a buffered result set(返回在緩衝結果集的行數)
  • sqlite_open — Opens an SQLite database and create the database if it does not exist(打開一個SQLite數據庫,創建數據庫,如果它不存在)
  • sqlite_popen — Opens a persistent handle to an SQLite database and create the database if it does not exist(打開一個持久句柄到SQLite數據庫,並創建數據庫,如果它不存在,)
  • sqlite_prev — Seek to the previous row number of a result set(尋求一個結果集的前行數)
  • sqlite_query — Executes a query against a given database and returns a result handle(執行針對給定的數據庫查詢並返回一個結果句柄)
  • sqlite_rewind — Seek to the first row number(求到所述第一行號)
  • sqlite_seek — Seek to a particular row number of a buffered result set(尋求一個緩衝的結果集的特定行號)
  • sqlite_single_query — Executes a query and returns either an array for one single column or the value of the first row(執行查詢,並返回任一個數組為一個單一的列或第一行的值)
  • sqlite_udf_decode_binary — Decode binary data passed as parameters to an UDF(解碼作為參數傳遞到一個UDF的二進制數據)
  • sqlite_udf_encode_binary — Encode binary data before returning it from an UDF(它從UDF返回之前編碼的二進制數據)
  • sqlite_unbuffered_query — Execute a query that does not prefetch and buffer all data(執行不預取的查詢和緩衝區中的所有數據)
  • sqlite_valid — Returns whether more rows are available(更多的行返回是否可)

One thought on “PHP:SQLite-Manual中存取函數轉貼

  1. SQLite – PHP
    資料來源:http://www.w3cschool.cc/sqlite/sqlite-php.html
    1 public void SQLite3::open ( filename, flags, encryption_key )
    打開一個 SQLite 3 資料庫。如果構建包括加密,那麼它將嘗試使用的密鑰。
    如果檔案名 filename 賦值為 ‘:memory:’,那麼 SQLite3::open() 將會在 RAM 中創建一個記憶體資料庫,這只會在 session 的有效時間內持續。
    如果檔案名 filename 為實際的設備檔案名稱,那麼 SQLite3::open() 將使用這個參數值嘗試打開資料庫檔。如果該名稱的檔不存在,那麼將創建一個新的命名為該名稱的資料庫檔。
    可選的 flags 用於判斷是否打開 SQLite 資料庫。默認情況下,當使用 SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE 時打開。
    2 public bool SQLite3::exec ( string $query )
    該常式提供了一個執行 SQL 命令的快捷方式,SQL 命令由 sql 參數提供,可以由多個 SQL 命令組成。該程式用於對給定的資料庫執行一個無結果的查詢。
    3 public SQLite3Result SQLite3::query ( string $query )
    該常式執行一個 SQL 查詢,如果查詢到返回結果則返回一個 SQLite3Result 物件。
    4 public int SQLite3::lastErrorCode ( void )
    該常式返回最近一次失敗的 SQLite 請求的數值結果代碼。
    5 public string SQLite3::lastErrorMsg ( void )
    該常式返回最近一次失敗的 SQLite 請求的英語文本描述。
    6 public int SQLite3::changes ( void )
    該常式返回最近一次的 SQL 語句更新或插入或刪除的資料庫行數。
    7 public bool SQLite3::close ( void )
    該常式關閉之前調用 SQLite3::open() 打開的資料庫連接。
    8 public string SQLite3::escapeString ( string $value )
    該常式返回一個字串,在 SQL 語句中,出於安全考慮,該字串已被正確地轉義。
    連接資料庫
    <I.>下面的 PHP 代碼顯示了如何連接到一個現有的資料庫。如果資料庫不存在,那麼它就會被創建,最後將返回一個資料庫物件。
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    ?>
    現在,讓我們來運行上面的程式,在當前目錄中創建我們的資料庫 test.db。您可以根據需要改變路徑。如果資料庫成功創建,那麼會顯示下面所示的消息:
    Open database successfully
    <II.>創建表
    下面的 PHP 代碼段將用於在先前創建的資料庫中創建一個表:
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    $sql =<<<EOF
    CREATE TABLE COMPANY
    (ID INT PRIMARY KEY NOT NULL,
    NAME TEXT NOT NULL,
    AGE INT NOT NULL,
    ADDRESS CHAR(50),
    SALARY REAL);
    EOF;
    $ret = $db->exec($sql);
    if(!$ret){
    echo $db->lastErrorMsg();
    } else {
    echo "Table created successfully\n";
    }
    $db->close();
    ?>
    上述程式執行時,它會在 test.db 中創建 COMPANY 表,並顯示下面所示的消息:
    Opened database successfully
    Table created successfully
    <III.>INSERT 操作
    下面的 PHP 程式顯示了如何在上面創建的 COMPANY 表中創建記錄:
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    $sql =<<<EOF
    INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
    VALUES (1, ‘Paul’, 32, ‘California’, 20000.00 );
    INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
    VALUES (2, ‘Allen’, 25, ‘Texas’, 15000.00 );
    INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
    VALUES (3, ‘Teddy’, 23, ‘Norway’, 20000.00 );
    INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
    VALUES (4, ‘Mark’, 25, ‘Rich-Mond ‘, 65000.00 );
    EOF;
    $ret = $db->exec($sql);
    if(!$ret){
    echo $db->lastErrorMsg();
    } else {
    echo "Records created successfully\n";
    }
    $db->close();
    ?>
    上述程式執行時,它會在 COMPANY 表中創建給定記錄,並會顯示以下兩行:
    Opened database successfully
    Records created successfully
    <IV.>SELECT 操作
    下面的 PHP 程式顯示了如何從前面創建的 COMPANY 表中獲取並顯示記錄:
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    $sql =<<<EOF
    SELECT * from COMPANY;
    EOF;
    $ret = $db->query($sql);
    while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
    echo "ID = ". $row[‘ID’] . "\n";
    echo "NAME = ". $row[‘NAME’] ."\n";
    echo "ADDRESS = ". $row[‘ADDRESS’] ."\n";
    echo "SALARY = ".$row[‘SALARY’] ."\n\n";
    }
    echo "Operation done successfully\n";
    $db->close();
    ?>
    上述程式執行時,它會產生以下結果:
    Opened database successfully
    ID = 1
    NAME = Paul
    ADDRESS = California
    SALARY = 20000
    ID = 2
    NAME = Allen
    ADDRESS = Texas
    SALARY = 15000
    ID = 3
    NAME = Teddy
    ADDRESS = Norway
    SALARY = 20000
    ID = 4
    NAME = Mark
    ADDRESS = Rich-Mond
    SALARY = 65000
    Operation done successfully
    <V.>UPDATE 操作
    下面的 PHP 代碼顯示了如何使用 UPDATE 語句來更新任何記錄,然後從 COMPANY 表中獲取並顯示更新的記錄:
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    $sql =<<<EOF
    UPDATE COMPANY set SALARY = 25000.00 where ID=1;
    EOF;
    $ret = $db->exec($sql);
    if(!$ret){
    echo $db->lastErrorMsg();
    } else {
    echo $db->changes(), " Record updated successfully\n";
    }
    $sql =<<<EOF
    SELECT * from COMPANY;
    EOF;
    $ret = $db->query($sql);
    while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
    echo "ID = ". $row[‘ID’] . "\n";
    echo "NAME = ". $row[‘NAME’] ."\n";
    echo "ADDRESS = ". $row[‘ADDRESS’] ."\n";
    echo "SALARY = ".$row[‘SALARY’] ."\n\n";
    }
    echo "Operation done successfully\n";
    $db->close();
    ?>
    上述程式執行時,它會產生以下結果:
    Opened database successfully
    1 Record updated successfully
    ID = 1
    NAME = Paul
    ADDRESS = California
    SALARY = 25000
    ID = 2
    NAME = Allen
    ADDRESS = Texas
    SALARY = 15000
    ID = 3
    NAME = Teddy
    ADDRESS = Norway
    SALARY = 20000
    ID = 4
    NAME = Mark
    ADDRESS = Rich-Mond
    SALARY = 65000
    Operation done successfully
    <VI.>DELETE 操作
    下面的 PHP 代碼顯示了如何使用 DELETE 語句刪除任何記錄,然後從 COMPANY 表中獲取並顯示剩餘的記錄:
    <?php
    class MyDB extends SQLite3
    {
    function __construct()
    {
    $this->open(‘test.db’);
    }
    }
    $db = new MyDB();
    if(!$db){
    echo $db->lastErrorMsg();
    } else {
    echo "Opened database successfully\n";
    }
    $sql =<<<EOF
    DELETE from COMPANY where ID=2;
    EOF;
    $ret = $db->exec($sql);
    if(!$ret){
    echo $db->lastErrorMsg();
    } else {
    echo $db->changes(), " Record deleted successfully\n";
    }
    $sql =<<<EOF
    SELECT * from COMPANY;
    EOF;
    $ret = $db->query($sql);
    while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
    echo "ID = ". $row[‘ID’] . "\n";
    echo "NAME = ". $row[‘NAME’] ."\n";
    echo "ADDRESS = ". $row[‘ADDRESS’] ."\n";
    echo "SALARY = ".$row[‘SALARY’] ."\n\n";
    }
    echo "Operation done successfully\n";
    $db->close();
    ?>
    上述程式執行時,它會產生以下結果:
    Opened database successfully
    1 Record deleted successfully
    ID = 1
    NAME = Paul
    ADDRESS = California
    SALARY = 25000
    ID = 3
    NAME = Teddy
    ADDRESS = Norway
    SALARY = 20000
    ID = 4
    NAME = Mark
    ADDRESS = Rich-Mond
    SALARY = 65000
    Operation done successfully

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *