Completed
Push — master ( 739816...7a9bed )
by joanhey
01:58
created

Kumbia/ActiveRecord/Query/pgsql_last_insert_id.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * KumbiaPHP web & app Framework.
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia
16
 *
17
 * @copyright  2005 - 2016  Kumbia Team (http://www.kumbiaphp.com)
18
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
19
 */
20
namespace Kumbia\ActiveRecord\Query;
21
22
/**
23
 * Obtiene el último id generado en pgsql.
24
 *
25
 * @param \PDO   $dbh    conexion pdo
26
 * @param string $pk     campo clave primaria
27
 * @param string $table  nombre de tabla
28
 * @param string $schema esquema
29
 *
30
 * @return string
31
 */
32
function pgsql_last_insert_id(\PDO $dbh, $pk, $table, $schema = null)
33
{
34
    $seq = "{$table}_{$pk}_seq";
35
    if ($schema) {
0 ignored issues
show
Bug Best Practice introduced by Joan Miquel
The expression $schema of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
36
        $seq = "$schema.$seq";
37
    }
38
39
    return $dbh->lastInsertId($seq);
40
}
41