tox2ik/php-mysqli-aliases

获取数组,插入值等

1.1.7 2018-09-07 21:51 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:26:05 UTC


README

不清楚原作者在2004年时的想法,但肯定不想写这样的事情只是为了填充一个记录的哈希表。

if ($db->query("INSERT INTO studends ... ;")) {
    if ($res = mysqli_insert_id($db)) {
        if ($qRes = $db->query("SELECT * FROM exam_results WHERE studint_id ...")) {
            while ($rec = mysqli_fetch_assoc($qRes)) {
                $rows[] = $rec
            }
        }
    }
}

这是可接受的

if (qInsert('insert into students ...;')) {
    $rows = qAssocAll("SELECT * FROM exam_results WHERE studint_id ...");
}

辅助工具

qArrayAll()              - get array (hydrate: both)
qAssocAll()              - get array (hydrate: associative)
qArrayColumnAll()        - get all values of a single column
qArrayOne()              - get a single record
qAssocOne()              - get a single record (assoc)
qOne()                   - get a single record (assoc)
qEscape()                - escape ' and "
qExists()                - get a true boolean if a query produces results
qInsert()                - get the last inserted id after inserting
qInsertId()              - get the last inserted id without inserting anything
qLastId()                - get the last inserted id without inserting anything
qResult()                - query and get a result set
qPrep()                  - prepare a statement
qExecutePrepared()       - yep
qUpdate()                - get the number of affected rows    
qVar()                   - get a single value
qError()                 - get last error

功能

  • 减少样板代码
  • 支持具有相同 接口 的 mysqli 和 PDO
  • 将所有 SQL 错误记录到 error_log 而不是使用 die()
  • 返回 array 而不是 false、空或不。
  • 将一列作为扁平列表获取
  • 获取单个值
  • 批量获取(无 while-fetch-one)
  • 如果您需要,则返回原始结果对象或资源