コード例 #1
0
 function delete($tabloAdi, $kosul)
 {
     $sql = "DELETE FROM " . $tabloAdi . " WHERE " . $kosul;
     if (!mysqli_real_query($this->baglantiNo, $sql)) {
         throw new DBException("Silme sorgusunda sorun var...");
     }
 }
コード例 #2
0
 function mysql_unbuffered_query($query, \mysqli $link = null)
 {
     $link = \Dshafik\MySQL::getConnection($link);
     if (mysqli_real_query($link, $query)) {
         return mysqli_use_result($link);
     }
     return false;
 }
コード例 #3
0
ファイル: mysql.inc.php プロジェクト: sakuraliu/bbs
function execute_bool($link, $query)
{
    $bool = mysqli_real_query($link, $query);
    if (mysqli_errno($link)) {
        exit(mysqli_error($link));
    }
    return $bool;
}
コード例 #4
0
ファイル: mysql.inc.php プロジェクト: Cafexss/MircoPush
function execute_bool($link, $query)
{
    // 此自定义函数的功能是返回一个布尔值的结果
    $bool = mysqli_real_query($link, $query);
    //使用自带的Mysqli函数
    if (mysqli_errno($link)) {
        exit(mysqli_error($link));
    }
    return $bool;
}
コード例 #5
0
function istable($table)
{
    global $mysqli;
    mysqli_real_query($mysqli, "SELECT 1 FROM `{$table}` LIMIT 1 ");
    mysqli_use_result($mysqli);
    if (mysqli_errno($mysqli) == 1146) {
        return false;
    } else {
        return true;
    }
}
コード例 #6
0
 public function __construct($cfg)
 {
     $link = @mysqli_connect($cfg['dbserver'], $cfg['dbuser'], $cfg['dbpass'], $cfg['dbname']);
     if ($link) {
         $this->linkid = $link;
         $this->connected = true;
         if (!empty($cfg['dbcharset'])) {
             mysqli_real_query($link, "SET NAMES '{$cfg['dbcharset']}'");
         }
     } else {
         $this->errnum = mysqli_connect_errno();
         $this->error = mysqli_connect_error();
     }
 }
コード例 #7
0
ファイル: mysqli.php プロジェクト: BackupTheBerlios/qsf-svn
 function query($query)
 {
     $args = array();
     if (is_array($query)) {
         $args = $query;
         // only use arg 1
     } else {
         $args = func_get_args();
     }
     $query = $this->_format_query($args);
     $this->querycount++;
     if (isset($this->get['debug'])) {
         $this->debug($query);
     }
     mysqli_real_query($this->connection, $query) or error(QUICKSILVER_QUERY_ERROR, mysqli_error($this->connection), $query, mysqli_errno($this->connection));
     return mysqli_store_result($this->connection);
 }
コード例 #8
0
 /**
  * Transaction style - runs queries in order
  *
  * @since 08.05.2011
  * Refactored for using $this::mysqli_connection instead of mysqli_init/mysqli_close
  */
 public function executeMultiNoresSQL(&$queryArry)
 {
     $link = $this->getMysqliConnection();
     /* set autocommit to off */
     mysqli_autocommit($link, FALSE);
     $all_query_ok = true;
     //do queries
     foreach ($queryArry as $query) {
         if (!mysqli_real_query($link, $query)) {
             $all_query_ok = false;
         }
     }
     if ($all_query_ok) {
         /* commit queries */
         mysqli_commit($link);
     } else {
         /* Rollback */
         mysqli_rollback($link);
     }
     /* set autocommit to on */
     mysqli_autocommit($link, TRUE);
     return $all_query_ok;
 }
コード例 #9
0
 public function executeMultiNoresSQL(&$queryArry)
 {
     $link = mysqli_init();
     if (!$link) {
         throw new DBAdapter2Exception("mysqli_init failed");
     }
     if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
         throw new DBAdapter2Exception("Setting MYSQLI_OPT_CONNECT_TIMEOUT failed");
     }
     if (!mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->schema)) {
         throw new DBAdapter2Exception('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     if (!mysqli_set_charset($link, $this->charset)) {
         throw new DBAdapter2Exception('Error loading character set ' . $this->charset . ' - ' . mysqli_error($link));
     }
     /* set autocommit to off */
     mysqli_autocommit($link, FALSE);
     $all_query_ok = true;
     //do queries
     foreach ($queryArry as $query) {
         if (!mysqli_real_query($link, $query)) {
             $all_query_ok = false;
         }
     }
     if ($all_query_ok) {
         /* commit queries */
         mysqli_commit($link);
     } else {
         /* Rollback */
         mysqli_rollback($link);
     }
     /* set autocommit to on */
     mysqli_autocommit($link, TRUE);
     mysqli_close($link);
     return $all_query_ok;
 }
コード例 #10
0
	margin-bottom: 3em;
}
.left {
	
}
.right {
	width: 60%;
}
</style>
<h1>Non-Auditioning Ents</h1>
<p> Download in <a href="nonAudition_Spreadsheet.php">spreadsheet format</a>. This is a tab separated file. In order to import it into excel (or similar software) correctly, make sure the 'tab' box is the only box checked for the delimiters (comma, space, etc should be unchecked).</p>
<table>
<?php 
$cv = mysqli_connect("localhost", "mayball_admin", "XuthebAw97");
mysqli_select_db($cv, "mayball");
mysqli_real_query($cv, "SELECT * FROM ents WHERE ents_slot_id=0;");
if ($result = mysqli_use_result($cv)) {
    while (($row = mysqli_fetch_assoc($result)) != null) {
        echo "<tr>";
        echo "<td class='right'>";
        echo "<span class='label'>Act Name</span>: " . $row["act_name"] . "<br />";
        echo "<span class='label'>Act Type</span>: " . $row["act_type"] . "<br />";
        echo "<span class='label'>Genre/Description</span>: <div id='genre'>" . nl2br($row["genre"]) . "</div><br />";
        echo "<span class='label'>Website</span>: <div id='genre'>" . nl2br($row["website"]) . "</div><br />";
        echo "<span class='label'>Performance Location</span>: <div id='genre'>" . nl2br($row["performance_location"]) . "</div><br />";
        echo "<span class='label'>Contact</span>: <a href='mailto:'" . $row["contact_email"] . "'>" . $row["contact_name"] . "</a> [" . $row["contact_phone"] . "] <br />";
        echo "</td>";
        echo "</tr>";
    }
}
mysqli_free_result($result);
コード例 #11
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_select_db($link, $db);
mysqli_query($link, "DROP TABLE IF EXISTS test_result");
mysqli_query($link, "CREATE TABLE test_result (a int, b varchar(10)) ENGINE = " . $engine);
mysqli_query($link, "INSERT INTO test_result VALUES (1, 'foo')");
mysqli_real_query($link, "SELECT * FROM test_result");
if (mysqli_field_count($link)) {
    $result = mysqli_store_result($link);
    $num = mysqli_num_fields($result);
    mysqli_free_result($result);
}
var_dump($num);
mysqli_query($link, "DROP TABLE IF EXISTS test_result");
mysqli_close($link);
コード例 #12
0
 public function executeSQL($query, &$resultArry, &$rowsAffected, $assoc = TRUE)
 {
     $l_iTries = 3;
     //times
     $l_iPause = 2;
     //seconds
     $l_bConnected = FALSE;
     //bool
     do {
         $link = mysqli_init();
         $rowsAffected = 0;
         if (!$link) {
             throw new DBAdapter2Exception("mysqli_init failed");
         }
         if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
             throw new DBAdapter2Exception("Setting MYSQLI_OPT_CONNECT_TIMEOUT failed");
         }
         if (!mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->schema)) {
             unset($link);
             sleep($l_iPause);
             $l_iTries = $l_iTries - 1;
         } else {
             $l_bConnected = TRUE;
             $l_iTries = 0;
         }
     } while (!$l_bConnected && $l_iTries > 0);
     if (!$l_bConnected) {
         throw new DBAdapter2Exception('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     if (!mysqli_set_charset($link, $this->charset)) {
         throw new DBAdapter2Exception('Error loading character set ' . $this->charset . ' - ' . mysqli_error($link));
     }
     //do queries
     if (mysqli_real_query($link, $query)) {
         //should be e proper select
         if (mysqli_field_count($link)) {
             //buffered
             $result = mysqli_store_result($link);
             if ($result) {
                 $resultArry = array();
                 $rowsAffected = mysqli_num_rows($result);
                 if ($assoc) {
                     while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                         $resultArry[] = $row;
                     }
                 } else {
                     while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
                         $resultArry[] = $row;
                     }
                 }
                 mysqli_free_result($result);
                 unset($result);
             }
         }
     } else {
         throw new DBAdapter2Exception('Error in query: ' . mysqli_error($link));
     }
     mysqli_close($link);
 }
コード例 #13
0
ファイル: dspurchase.php プロジェクト: michaelprem/phc
    // End of for $i < count($item)
    $orderlines_insert[strlen($orderlines_insert) - 1] = ";";
    $cust_hist_insert[strlen($cust_hist_insert) - 1] = ";";
    if (!mysqli_real_query($link_id_trans, $orderlines_insert)) {
        echo "Insert into ORDERLINES table failed:  query= {$orderlines_insert}\n";
        $success = false;
    }
    if ($success) {
        mysqli_commit($link_id_trans);
    } else {
        mysqli_rollback($link_id_trans);
    }
    mysqli_close($link_id_trans);
    // Do CUST_HIST insert outside of transaction for performance
    mysqli_real_query($link_id, $cust_hist_insert);
    if ($success) {
        // To Do: verify credit card purchase against a second database
        $cctypes = array("MasterCard", "Visa", "Discover", "Amex", "Dell Preferred");
        $cc_query = "select CREDITCARDTYPE, CREDITCARD, CREDITCARDEXPIRATION from DS2.CUSTOMERS where CUSTOMERID={$customerid}";
        mysqli_real_query($link_id, $cc_query);
        $cc_result = mysqli_store_result($link_id);
        $cc_result_row = mysqli_fetch_row($cc_result);
        mysqli_free_result($cc_result);
        echo "<H3>\$" . $totalamount_fmt . " charged to credit card {$cc_result_row['1']} " . "(" . $cctypes[$cc_result_row[0] - 1] . "), expiration {$cc_result_row['2']}</H3><BR>\n";
        echo "<H2>Order Completed Successfully --- ORDER NUMBER:  {$orderid}</H2><BR>\n";
    } else {
        echo "<H3>Insufficient stock - order not processed</H3>\n";
    }
}
ds_html_footer();
mysqli_close($link_id);
require_once 'table.inc';
$references = array();
if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1") || !($res = mysqli_store_result($link))) {
    printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$idx = 0;
while ($row = mysqli_fetch_assoc($res)) {
    /* will overwrite itself */
    $references[$idx]['row_ref'] =& $row;
    $references[$idx]['row_copy'] = $row;
    $references[$idx]['id_ref'] =& $row['id'];
    $references[$idx++]['id_copy'] = $row['id'];
}
debug_zval_dump($references);
mysqli_free_result($res);
if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") || !($res = mysqli_use_result($link))) {
    printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$rows = array();
for ($i = 0; $i < 2; $i++) {
    $rows[$i] = mysqli_fetch_assoc($res);
    $references[$idx]['row_ref'] =& $rows[$i];
    $references[$idx]['row_copy'] = $rows[$i];
    $references[$idx]['id_ref'] =& $rows[$i]['id'];
    $references[$idx]['id_copy'] = $rows[$i]['id'];
    /* enforce separation */
    $references[$idx]['id_copy_mod'] = $rows[$i]['id'] + 0;
}
mysqli_free_result($res);
debug_zval_dump($references);
print "done!";
コード例 #15
0
        mysqli_real_query($link, 'SELECT @version AS p_version');
        $res = mysqli_store_result($link);
        $tmp = mysqli_fetch_assoc($res);
        if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || '' == $tmp['p_version']) {
            printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
            var_dump($tmp);
        }
        mysqli_free_result($res);
    } else {
        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    mysqli_real_query($link, 'DROP FUNCTION IF EXISTS f');
    if (mysqli_real_query($link, 'CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN
ver_param;')) {
        mysqli_real_query($link, 'SELECT f(VERSION()) AS f_version');
        $res = mysqli_store_result($link);
        $tmp = mysqli_fetch_assoc($res);
        if (!is_array($tmp) || empty($tmp) || !isset($tmp['f_version']) || '' == $tmp['f_version']) {
            printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
            var_dump($tmp);
        }
        mysqli_free_result($res);
    } else {
        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
}
mysqli_close($link);
if (NULL !== ($tmp = mysqli_real_query($link, "SELECT id FROM test"))) {
    printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
print "done!";
<?php

require_once 'connect.inc';
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) {
    printf("[003] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
}
if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) {
    if (!($stmt = mysqli_prepare($link, 'CALL p(?, ?)'))) {
        printf("[005] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    $ver_in = 'myversion';
    $ver_out = '';
    if (!mysqli_stmt_bind_param($stmt, 'ss', $ver_in, $ver_out)) {
        printf("[006] Cannot bind parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if (!mysqli_stmt_execute($stmt)) {
        printf("[007] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    printf("[008] More results: %s\n", mysqli_more_results($link) ? "yes" : "no");
    printf("[009] Next results: %s\n", mysqli_next_result($link) ? "yes" : "no");
    if (!mysqli_stmt_bind_result($stmt, $ver_out) || !mysqli_stmt_fetch($stmt)) {
        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if ("myversion" !== $ver_out) {
        printf("[011] Results seem wrong got '%s'\n", $ver_out);
    }
    if (!mysqli_stmt_close($stmt)) {
        printf("[012] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
コード例 #17
0
mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA);
if (mysqli_get_server_version($link) > 50000) {
    // let's try to play with stored procedures
    mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p');
    if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) READS SQL DATA BEGIN SELECT id FROM test WHERE id >= 100 ORDER BY id; SELECT id + 1, label FROM test WHERE id > 0 AND id < 3 ORDER BY id; SELECT VERSION() INTO ver_param;
END;')) {
        mysqli_multi_query($link, "CALL p(@version)");
        do {
            if ($res = $link->store_result(MYSQLI_STORE_RESULT_COPY_DATA)) {
                printf("---\n");
                var_dump($res->fetch_all());
                $res->free();
            } else {
                if ($link->errno) {
                    echo "Store failed: (" . $link->errno . ") " . $link->error;
                }
            }
        } while ($link->more_results() && $link->next_result());
        mysqli_real_query($link, 'SELECT @version AS p_version');
        $res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA);
        $tmp = mysqli_fetch_assoc($res);
        if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || '' == $tmp['p_version']) {
            printf("[024] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
            var_dump($tmp);
        }
        mysqli_free_result($res);
    } else {
        printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
}
print "done!";
コード例 #18
0
/**
 * @param $sql
 * @param $paras
 * @return bool|string
 */
function db_write($sql, $paras)
{
    if (dbconfig_w::Provider == "mysqli") {
        //mysqli的情况
        if (extension_loaded("mysqli")) {
            $con = mysqli_connect(dbconfig_w::DataSource, dbconfig_w::UserID, dbconfig_w::Password, dbconfig_w::InitialCatalog, dbconfig_w::Port);
            if ($con != false) {
                if ($paras == null) {
                    $rel = mysqli_real_query($con, $sql);
                    $data = false;
                    if ($rel != false) {
                        $data = $rel;
                    } else {
                        $data = dberror::SQL_EXCEPTION;
                    }
                } else {
                    $mt = $con->stmt_init();
                    $mt->prepare($sql);
                    foreach ($paras as $para) {
                        $val = $para->value;
                        mysqli_stmt_bind_param($mt, $para->type, $val);
                    }
                    unset($para);
                    $rel = mysqli_stmt_execute($mt);
                    if ($rel != false) {
                        $data = $rel;
                    } else {
                        return dberror::SQL_EXCEPTION;
                    }
                }
                mysqli_close($con);
                return $data;
            } else {
                return dberror::CONNECT_EXCEPTION;
            }
        } else {
            return dberror::NO_MYSQLI_EXCEPTION;
        }
    } else {
        //mysql的情况
        if (extension_loaded("mysql")) {
            $con = mysql_connect(dbconfig_w::DataSource, dbconfig_w::UserID, dbconfig_w::Password, dbconfig_w::InitialCatalog, dbconfig_w::Port);
            if ($con != false) {
                if ($paras == null) {
                    $rel = mysql_query($con, $sql);
                    $data = false;
                    if ($rel != false) {
                        $data = true;
                    } else {
                        $data = dberror::SQL_EXCEPTION;
                    }
                } else {
                    $data = dberror::MYSQL_NO_PREPARE_EXCEPTION;
                }
                mysql_close($con);
                return $data;
            } else {
                return dberror::CONNECT_EXCEPTION;
            }
        } else {
            return dberror::NO_MYSQL_EXCEPTION;
        }
    }
}
コード例 #19
0
mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db);
mysqli_kill($link, -1);
// mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it
mysqli_real_query($link, "FOO");
if (@mysqli_select_db($link, "Oh lord, let this be an unknown database name")) {
    printf("[009] select_db should have failed\n");
}
// mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it
// Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would
// not have been set. If that would be the case, the test would be broken.
mysqli_report(MYSQLI_REPORT_OFF);
mysqli_multi_query($link, "BAR; FOO;");
mysqli_query($link, "FOO");
mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
mysqli_kill($link, -1);
mysqli_real_query($link, "FOO");
mysqli_select_db($link, "Oh lord, let this be an unknown database name");
mysqli_report(MYSQLI_REPORT_OFF);
mysqli_report(MYSQLI_REPORT_STRICT);
try {
    if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) {
        printf("[010] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", $host, $user . 'unknown_really', $db, $port, $socket);
    }
    mysqli_close($link);
} catch (mysqli_sql_exception $e) {
    printf("[011] %s\n", $e->getMessage());
}
try {
    if (!($link = mysqli_init())) {
        printf("[012] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
    }
コード例 #20
0
ファイル: 037.php プロジェクト: alphaxxl/hhvm
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_select_db($link, $db);
mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1");
mysqli_query($link, "CREATE TABLE test_037_table_1 (a int, b varchar(10)) ENGINE = " . $engine);
mysqli_query($link, "INSERT INTO test_037_table_1 VALUES (1, 'foo')");
$ir[] = mysqli_field_count($link);
mysqli_real_query($link, "SELECT * FROM test_037_table_1");
$ir[] = mysqli_field_count($link);
var_dump($ir);
mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1");
mysqli_close($link);
print "done!";
require_once "connect.inc";
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_037_table_1")) {
    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_close($link);
コード例 #21
0
ファイル: 039.php プロジェクト: badlamer/hhvm
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_real_query($link, "SHOW VARIABLES");
if (mysqli_field_count($link)) {
    $result = mysqli_store_result($link);
    $num = mysqli_num_fields($result);
    mysqli_free_result($result);
}
var_dump($num);
mysqli_close($link);
print "done!";
コード例 #22
0
ファイル: mysqli.php プロジェクト: samuell/Core
 /**
  * This method is the central method for handling database
  * interaction. The method can be used for setting up a database
  * connection, for running a SQL query and for returning query rows.
  * Which of these actions the method will handle and what the method
  * return data will be, is determined by the $return method parameter.
  *
  * @param $return   - What to return. Options are the following constants:
  *                    DB_RETURN_CONN      a db connection handle
  *                    DB_RETURN_QUOTED    a quoted parameter
  *                    DB_RETURN_RES       result resource handle
  *                    DB_RETURN_ROW       single row as array
  *                    DB_RETURN_ROWS      all rows as arrays
  *                    DB_RETURN_ASSOC     single row as associative array
  *                    DB_RETURN_ASSOCS    all rows as associative arrays
  *                    DB_RETURN_VALUE     single row, single column
  *                    DB_RETURN_ROWCOUNT  number of selected rows
  *                    DB_RETURN_NEWID     new row id for insert query
  *                    DB_RETURN_ERROR     an error message if the query
  *                                        failed or NULL if there was
  *                                        no error
  *                    DB_CLOSE_CONN       close the connection, no
  *                                        return data
  *
  * @param $sql      - The SQL query to run or the parameter to quote if
  *                    DB_RETURN_QUOTED is used.
  *
  * @param $keyfield - When returning an array of rows, the indexes are
  *                    numerical by default (0, 1, 2, etc.). However, if
  *                    the $keyfield parameter is set, then from each
  *                    row the $keyfield index is taken as the key for the
  *                    return array. This way, you can create a direct
  *                    mapping between some id field and its row in the
  *                    return data. Mind that there is no error checking
  *                    at all, so you have to make sure that you provide
  *                    a valid $keyfield here!
  *
  * @param $flags    - Special flags for modifying the method's behavior.
  *                    These flags can be OR'ed if multiple flags are needed.
  *                    DB_NOCONNECTOK     Failure to connect is not fatal
  *                                       but lets the call return FALSE
  *                                       (useful in combination with
  *                                       DB_RETURN_CONN).
  *                    DB_MISSINGTABLEOK  Missing table errors not fatal.
  *                    DB_DUPFIELDNAMEOK  Duplicate field errors not fatal.
  *                    DB_DUPKEYNAMEOK    Duplicate key name errors
  *                                       not fatal.
  *                    DB_DUPKEYOK        Duplicate key errors not fatal.
  *
  * @param $limit    - The maximum number of rows to return.
  * @param $offset   - The number of rows to skip in the result set,
  *                    before returning rows to the caller.
  *
  * @return $res     - The result of the query, based on the $return
  *                    parameter.
  */
 public function interact($return, $sql = NULL, $keyfield = NULL, $flags = 0, $limit = 0, $offset = 0)
 {
     static $conn;
     static $querytrack;
     // Close the database connection.
     if ($return == DB_CLOSE_CONN) {
         if (!empty($conn)) {
             mysqli_close($conn);
             $conn = null;
         }
         return;
     }
     $debug = empty($GLOBALS['PHORUM']['DBCONFIG']['dbdebug']) ? 0 : $GLOBALS['PHORUM']['DBCONFIG']['dbdebug'];
     if (!empty($debug)) {
         if (!isset($querytrack) || !is_array($querytrack)) {
             $querytrack = array('count' => 0, 'time' => 0, 'queries' => array());
         }
     }
     // Setup a database connection if no database connection is
     // available yet.
     if (empty($conn)) {
         global $PHORUM;
         // we suppress errors from the mysqli_connect command as errors
         // are catched differently.
         $conn = mysqli_connect($PHORUM['DBCONFIG']['server'], $PHORUM['DBCONFIG']['user'], $PHORUM['DBCONFIG']['password'], $PHORUM['DBCONFIG']['name'], $PHORUM['DBCONFIG']['port'], $PHORUM['DBCONFIG']['socket']);
         if ($conn === FALSE) {
             if ($flags & DB_NOCONNECTOK) {
                 return FALSE;
             }
             phorum_api_error(PHORUM_ERRNO_DATABASE, 'Failed to connect to the database.');
             exit;
         }
         if (!empty($PHORUM['DBCONFIG']['charset'])) {
             $set_names = "SET NAMES '{$PHORUM['DBCONFIG']['charset']}'";
             mysqli_query($conn, $set_names);
             if ($debug) {
                 $querytrack['count'] += 2;
                 if ($debug > 1) {
                     $querytrack['queries'][] = array('number' => '001', 'query' => htmlspecialchars($set_names), 'raw_query' => $set_names, 'time' => '0.000');
                 }
             }
         }
         // putting this here for testing mainly
         // All of Phorum should work in strict mode
         if (!empty($PHORUM["DBCONFIG"]["strict_mode"])) {
             mysqli_query($conn, "SET SESSION sql_mode='STRICT_ALL_TABLES'");
         }
     }
     // RETURN: quoted parameter.
     if ($return === DB_RETURN_QUOTED) {
         return mysqli_real_escape_string($conn, $sql);
     }
     // RETURN: database connection handle
     if ($return === DB_RETURN_CONN) {
         return $conn;
     }
     // By now, we really need a SQL query.
     if ($sql === NULL) {
         trigger_error(__METHOD__ . ': Internal error: ' . 'missing sql query statement!', E_USER_ERROR);
     }
     // Apply limit and offset to the query.
     settype($limit, 'int');
     settype($offset, 'int');
     if ($limit > 0) {
         $sql .= " LIMIT {$limit}";
     }
     if ($offset > 0) {
         $sql .= " OFFSET {$offset}";
     }
     // Execute the SQL query.
     $tries = 0;
     $res = FALSE;
     while ($res === FALSE && $tries < 3) {
         // Time the query for debug level 2 and up.
         if ($debug > 1) {
             $t1 = microtime(TRUE);
         }
         // For queries where we are going to retrieve multiple rows, we
         // use an unuffered query result.
         if ($return === DB_RETURN_ASSOCS || $return === DB_RETURN_ROWS) {
             $res = FALSE;
             if (mysqli_real_query($conn, $sql) !== FALSE) {
                 $res = mysqli_use_result($conn);
             }
         } else {
             $res = mysqli_query($conn, $sql);
         }
         if ($debug) {
             $querytrack['count']++;
             if ($debug > 1) {
                 $t2 = microtime(TRUE);
                 $time = sprintf("%0.3f", $t2 - $t1);
                 $querytrack['time'] += $time;
                 $querytrack['queries'][] = array('number' => sprintf("%03d", $querytrack['count']), 'query' => htmlspecialchars($sql), 'raw_query' => $sql, 'time' => $time);
             }
             $GLOBALS['PHORUM']['DATA']['DBDEBUG'] = $querytrack;
         }
         // Handle errors.
         if ($res === FALSE) {
             $errno = mysqli_errno($conn);
             // if we have an error due to a transactional storage engine,
             // retry the query for those errors up to 2 more times
             if ($tries < 3 && ($errno == 1422 || $errno == 1213 || $errno == 1205)) {
                 // 1205 Lock wait timeout
                 $tries++;
             } else {
                 // See if the $flags tell us to ignore the error.
                 $ignore_error = FALSE;
                 switch ($errno) {
                     // Table does not exist.
                     case 1146:
                         if ($flags & DB_MISSINGTABLEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Table already exists.
                     // Table already exists.
                     case 1050:
                         if ($flags & DB_TABLEEXISTSOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate column name.
                     // Duplicate column name.
                     case 1060:
                         if ($flags & DB_DUPFIELDNAMEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate key name.
                     // Duplicate key name.
                     case 1061:
                         if ($flags & DB_DUPKEYNAMEOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                         // Duplicate entry for key.
                     // Duplicate entry for key.
                     case 1062:
                         // For MySQL server versions 5.1.15 up to 5.1.20. See
                         // bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
                     // For MySQL server versions 5.1.15 up to 5.1.20. See
                     // bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
                     case 1582:
                         if ($flags & DB_DUPKEYOK) {
                             $ignore_error = TRUE;
                         }
                         break;
                 }
                 // Handle this error if it's not to be ignored.
                 if (!$ignore_error) {
                     $err = mysqli_error($conn);
                     // RETURN: error message.
                     if ($return === DB_RETURN_ERROR) {
                         return $err;
                     }
                     // Trigger an error.
                     phorum_api_error(PHORUM_ERRNO_DATABASE, "{$err} ({$errno}): {$sql}");
                     exit;
                 }
                 // break while
                 break;
             }
         }
     }
     // RETURN: NULL (no error).
     if ($return === DB_RETURN_ERROR) {
         return NULL;
     }
     // RETURN: query resource handle
     if ($return === DB_RETURN_RES) {
         return $res;
     }
     // RETURN: number of rows
     if ($return === DB_RETURN_ROWCOUNT) {
         return $res ? mysqli_num_rows($res) : 0;
     }
     // RETURN: array rows or single value
     if ($return === DB_RETURN_ROW || $return === DB_RETURN_ROWS || $return === DB_RETURN_VALUE) {
         // Keyfields are only valid for DB_RETURN_ROWS.
         if ($return !== DB_RETURN_ROWS) {
             $keyfield = NULL;
         }
         $rows = array();
         if ($res) {
             while ($row = mysqli_fetch_row($res)) {
                 if ($keyfield === NULL) {
                     $rows[] = $row;
                 } else {
                     $rows[$row[$keyfield]] = $row;
                 }
             }
         }
         // Return all rows.
         if ($return === DB_RETURN_ROWS) {
             /* Might be FALSE in case of ignored errors. */
             if (!is_bool($res)) {
                 mysqli_free_result($res);
             }
             return $rows;
         }
         // Return a single row.
         if ($return === DB_RETURN_ROW) {
             if (count($rows) == 0) {
                 return NULL;
             } else {
                 return $rows[0];
             }
         }
         // Return a single value.
         if (count($rows) == 0) {
             return NULL;
         } else {
             return $rows[0][0];
         }
     }
     // RETURN: associative array rows
     if ($return === DB_RETURN_ASSOC || $return === DB_RETURN_ASSOCS) {
         // Keyfields are only valid for DB_RETURN_ASSOCS.
         if ($return !== DB_RETURN_ASSOCS) {
             $keyfield = NULL;
         }
         $rows = array();
         if ($res) {
             while ($row = mysqli_fetch_assoc($res)) {
                 if ($keyfield === NULL) {
                     $rows[] = $row;
                 } else {
                     $rows[$row[$keyfield]] = $row;
                 }
             }
         }
         // Return all rows.
         if ($return === DB_RETURN_ASSOCS) {
             /* Might be FALSE in case of ignored errors. */
             if (!is_bool($res)) {
                 mysqli_free_result($res);
             }
             return $rows;
         }
         // Return a single row.
         if ($return === DB_RETURN_ASSOC) {
             if (count($rows) == 0) {
                 return NULL;
             } else {
                 return $rows[0];
             }
         }
     }
     // RETURN: new id after inserting a new record
     if ($return === DB_RETURN_NEWID) {
         return mysqli_insert_id($conn);
     }
     trigger_error(__METHOD__ . ': Internal error: ' . 'illegal return type specified!', E_USER_ERROR);
 }
コード例 #23
0
            $amount = str_replace(',', '.', $_POST['amount']);
        } else {
            exit('Fehler: Kosten');
        }
    } else {
        $amount = $_POST['amount'];
    }
    $query = 'UPDATE
                  costs_person
                SET
                  costs_person.year = \'' . $_POST['year'] . '\',
                  costs_person.usage = \'' . $post_usage . '\',
                  costs_person.amount = \'' . $amount . '\'
                WHERE
                  costs_person.id = ' . $_GET['param'];
    $result = mysqli_real_query($db, $query);
}
$query_costs = 'SELECT
                      costs_person.year, costs_person.usage, costs_person.amount
                    FROM
                      costs_person
                    WHERE costs_person.id =' . $_GET['param'];
$result_costs = mysqli_query($db, $query_costs);
mysqli_close($db);
echo '<body';
if ($result) {
    echo ' onload="window.opener.location.href=\'costs_person.php\'; window.close();"';
}
echo '>';
echo '<div class="head">
            <h1>Kosten pro Person ändern</h1>
コード例 #24
0
ファイル: bug34785.php プロジェクト: alphaxxl/hhvm
include "connect.inc";
class my_stmt extends mysqli_stmt
{
    public function __construct($link, $query)
    {
        parent::__construct($link, $query);
    }
}
class my_result extends mysqli_result
{
    public function __construct($link, $query)
    {
        parent::__construct($link, $query);
    }
}
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
mysqli_query($link, "SET sql_mode=''");
$stmt = new my_stmt($link, "SELECT 'foo' FROM test_bug34785_table_1");
$stmt->execute();
$stmt->bind_result($var);
$stmt->fetch();
$stmt->close();
var_dump($var);
mysqli_real_query($link, "SELECT 'bar' FROM test_bug34785_table_1");
$result = new my_result($link, MYSQLI_STORE_RESULT);
$row = $result->fetch_row();
$result->close();
var_dump($row[0]);
mysqli_close($link);
コード例 #25
0
	margin-bottom: 3em;
}
.left {
	
}
.right {
	width: 60%;
}
</style>
<h1>Ents Bookings</h1>
<p> Download in <a href="bookings_Spreadsheet.php">spreadsheet format</a>. This is a tab separated file. In order to import it into excel (or similar software) correctly, make sure the 'tab' box is the only box checked for the delimiters (comma, space, etc should be unchecked).</p>
<table>
<?php 
$cv = mysqli_connect("localhost", "mayball_admin", "XuthebAw97");
mysqli_select_db($cv, "mayball");
mysqli_real_query($cv, "SELECT ents_slots.*,ents.* FROM ents INNER JOIN ents_slots ON ents.ents_slot_id=ents_slots.ents_slot_id ORDER BY ents_slots.time;");
if ($result = mysqli_use_result($cv)) {
    while (($row = mysqli_fetch_assoc($result)) != null) {
        echo "<tr>";
        echo "<td class='left'>" . date("D jS M - g:i a", strtotime($row["time"])) . "</td>";
        echo "<td class='right'>";
        echo "<span class='label'>Act Name</span>: " . $row["act_name"] . "<br />";
        echo "<span class='label'>Act Type</span>: " . $row["act_type"] . "<br />";
        echo "<span class='label'>Genre/Description</span>: <div id='genre'>" . nl2br($row["genre"]) . "</div><br />";
        echo "<span class='label'>Contact</span>: <a href='mailto:'" . $row["contact_email"] . "'>" . $row["contact_name"] . "</a> [" . $row["contact_phone"] . "] <br />";
        echo "</td>";
        echo "</tr>";
    }
}
mysqli_free_result($result);
?>
コード例 #26
0
ファイル: mysqli_use_result.php プロジェクト: alphaxxl/hhvm
<?php

require_once "connect.inc";
$tmp = NULL;
$link = NULL;
$test_table_name = 'test_mysqli_use_result_table_1';
require 'table.inc';
if (!($res = mysqli_real_query($link, "SELECT id, label FROM test_mysqli_use_result_table_1 ORDER BY id"))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_use_result($link))) {
    printf("[004] Expecting object, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
if (false !== ($tmp = mysqli_data_seek($res, 2))) {
    printf("[005] Expecting boolean/true, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
if (!mysqli_query($link, "DELETE FROM test_mysqli_use_result_table_1")) {
    printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (false !== ($res = mysqli_use_result($link))) {
    printf("[007] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
if (!($res = mysqli_query($link, "SELECT id, label FROM test_mysqli_use_result_table_1 ORDER BY id"))) {
    printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (false !== ($tmp = mysqli_data_seek($res, 1))) {
    printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
if (NULL !== ($tmp = mysqli_use_result($link))) {
コード例 #27
0
$test_table_name = 'test_mysqli_poll_mixing_insert_select_table_1';
require_once 'table.inc';
function get_connection()
{
    global $host, $user, $passwd, $db, $port, $socket;
    if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
        printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
    }
    return $link;
}
// Note: some queries will fail! They are supposed to fail.
$queries = array('CREATE TABLE IF NOT EXISTS test_mysqli_poll_mixing_insert_select_table_2(id INT)', 'SET @a = 1', 'SELECT * FROM test_mysqli_poll_mixing_insert_select_table_1 ORDER BY id ASC LIMIT 2', "INSERT INTO test_mysqli_poll_mixing_insert_select_table_1(id, label) VALUES (100, 'z')", 'SELECT * FROM test_mysqli_poll_mixing_insert_select_table_1 ORDER BY id ASC LIMIT 2', 'SELECT', 'UPDATE test_mysqli_poll_mixing_insert_select_table_1 SET id = 101 WHERE id > 3', 'UPDATE_FIX test_mysqli_poll_mixing_insert_select_table_1 SET id = 101 WHERE id > 3', 'DROP TABLE IF EXISTS test_mysqli_poll_mixing_insert_select_table_2', 'DELETE FROM test_mysqli_poll_mixing_insert_select_table_1 WHERE id = @a', 'DELETE FROM test_mysqli_poll_mixing_insert_select_table_1 WHERE id = 1');
$link = get_connection();
$have_proc = false;
mysqli_real_query($link, "DROP PROCEDURE IF EXISTS test_mysqli_poll_mixing_insert_select_procedure_1");
if (mysqli_real_query($link, 'CREATE PROCEDURE test_mysqli_poll_mixing_insert_select_procedure_1(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) {
    $have_proc = true;
    $queries[] = "CALL test_mysqli_poll_mixing_insert_select_procedure_1('myversion', @version)";
}
mysqli_close($link);
$links = array();
for ($i = 0; $i < count($queries); $i++) {
    $link = get_connection();
    if (true !== ($tmp = mysqli_query($link, $queries[$i], MYSQLI_ASYNC | MYSQLI_USE_RESULT))) {
        printf("[002] Expecting true got %s/%s\n", gettype($tmp), var_export($tmp, true));
    }
    // WARNING KLUDGE NOTE
    // Add a tiny delay to ensure that queries get executed in a certain order
    // If your MySQL server is very slow the test may randomly fail!
    usleetest_mysqli_poll_mixing_insert_select_procedure_1(20000);
    $links[mysqli_thread_id($link)] = array('query' => $queries[$i], 'link' => $link, 'processed' => false);
コード例 #28
0
ファイル: mysqli.php プロジェクト: sheldon/dejavu
/**
 * This function is the central function for handling database interaction.
 * The function can be used for setting up a database connection, for running
 * a SQL query and for returning query rows. Which of these actions the
 * function will handle and what the function return data will be, is
 * determined by the $return function parameter.
 *
 * @param $return   - What to return. Options are the following constants:
 *                    DB_RETURN_CONN      a db connection handle
 *                    DB_RETURN_QUOTED    a quoted parameter
 *                    DB_RETURN_RES       result resource handle
 *                    DB_RETURN_ROW       single row as array
 *                    DB_RETURN_ROWS      all rows as arrays
 *                    DB_RETURN_ASSOC     single row as associative array
 *                    DB_RETURN_ASSOCS    all rows as associative arrays
 *                    DB_RETURN_VALUE     single row, single column
 *                    DB_RETURN_ROWCOUNT  number of selected rows
 *                    DB_RETURN_NEWID     new row id for insert query
 *                    DB_RETURN_ERROR     an error message if the query
 *                                        failed or NULL if there was no error
 *                    DB_CLOSE_CONN       close the connection, no return data
 *
 * @param $sql      - The SQL query to run or the parameter to quote if
 *                    DB_RETURN_QUOTED is used.
 *
 * @param $keyfield - When returning an array of rows, the indexes are
 *                    numerical by default (0, 1, 2, etc.). However, if
 *                    the $keyfield parameter is set, then from each
 *                    row the $keyfield index is taken as the key for the
 *                    return array. This way, you can create a direct
 *                    mapping between some id field and its row in the
 *                    return data. Mind that there is no error checking
 *                    at all, so you have to make sure that you provide
 *                    a valid $keyfield here!
 *
 * @param $flags    - Special flags for modifying the function's behavior.
 *                    These flags can be OR'ed if multiple flags are needed.
 *                    DB_NOCONNECTOK     Failure to connect is not fatal but
 *                                       lets the call return FALSE (useful
 *                                       in combination with DB_RETURN_CONN).
 *                    DB_MISSINGTABLEOK  Missing table errors not fatal.
 *                    DB_DUPFIELDNAMEOK  Duplicate field errors not fatal.
 *                    DB_DUPKEYNAMEOK    Duplicate key name errors not fatal.
 *                    DB_DUPKEYOK        Duplicate key errors not fatal.
 *
 * @return $res     - The result of the query, based on the $return parameter.
 */
function phorum_db_interact($return, $sql = NULL, $keyfield = NULL, $flags = 0)
{
    static $conn;
    // Close the database connection.
    if ($return == DB_CLOSE_CONN) {
        if (!empty($conn)) {
            mysqli_close($conn);
            $conn = null;
        }
        return;
    }
    // Setup a database connection if no database connection is available yet.
    if (empty($conn)) {
        $PHORUM = $GLOBALS['PHORUM'];
        $conn = mysqli_connect($PHORUM['DBCONFIG']['server'], $PHORUM['DBCONFIG']['user'], $PHORUM['DBCONFIG']['password'], $PHORUM['DBCONFIG']['name'], $PHORUM['DBCONFIG']['port'], $PHORUM['DBCONFIG']['socket']);
        if ($conn === FALSE) {
            if ($flags & DB_NOCONNECTOK) {
                return FALSE;
            }
            phorum_database_error('Failed to connect to the database.');
            exit;
        }
        if (!empty($PHORUM['DBCONFIG']['charset'])) {
            mysqli_query($conn, "SET NAMES '{$PHORUM['DBCONFIG']['charset']}'");
        }
        // putting this here for testing mainly
        // All of Phorum should work in strict mode
        if (!empty($PHORUM["DBCONFIG"]["strict_mode"])) {
            mysqli_query($conn, "SET SESSION sql_mode='STRICT_ALL_TABLES'");
        }
    }
    // Return a quoted parameter.
    if ($return === DB_RETURN_QUOTED) {
        return mysqli_real_escape_string($conn, $sql);
    }
    // RETURN: database connection handle
    if ($return === DB_RETURN_CONN) {
        return $conn;
    }
    // By now, we really need a SQL query.
    if ($sql === NULL) {
        trigger_error('Internal error: phorum_db_interact(): ' . 'missing sql query statement!', E_USER_ERROR);
    }
    // Execute the SQL query.
    // For queries where we are going to retrieve multiple rows, we
    // use an unuffered query result.
    if ($return === DB_RETURN_ASSOCS || $return === DB_RETURN_ROWS) {
        $res = FALSE;
        if (mysqli_real_query($conn, $sql) !== FALSE) {
            $res = mysqli_use_result($conn);
        }
    } else {
        $res = mysqli_query($conn, $sql);
    }
    // Execute the SQL query.
    if ($res === FALSE) {
        // See if the $flags tell us to ignore the error.
        $ignore_error = FALSE;
        $errno = mysqli_errno($conn);
        switch ($errno) {
            // Table does not exist.
            case 1146:
                if ($flags & DB_MISSINGTABLEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Table already exists.
            // Table already exists.
            case 1050:
                if ($flags & DB_TABLEEXISTSOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate column name.
            // Duplicate column name.
            case 1060:
                if ($flags & DB_DUPFIELDNAMEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate key name.
            // Duplicate key name.
            case 1061:
                if ($flags & DB_DUPKEYNAMEOK) {
                    $ignore_error = TRUE;
                }
                break;
                // Duplicate entry for key.
            // Duplicate entry for key.
            case 1062:
                // For MySQL server versions 5.1.15 up to 5.1.20.
                // See bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
            // For MySQL server versions 5.1.15 up to 5.1.20.
            // See bug #28842 (http://bugs.mysql.com/bug.php?id=28842)
            case 1582:
                if ($flags & DB_DUPKEYOK) {
                    $ignore_error = TRUE;
                }
                break;
        }
        // Handle this error if it's not to be ignored.
        if (!$ignore_error) {
            $err = mysqli_error($conn);
            // RETURN: error message or NULL
            if ($return === DB_RETURN_ERROR) {
                return $err;
            }
            // Trigger an error.
            phorum_database_error("{$err} ({$errno}): {$sql}");
            exit;
        }
    }
    // RETURN: error message or NULL
    if ($return === DB_RETURN_ERROR) {
        return NULL;
    }
    // RETURN: query resource handle
    if ($return === DB_RETURN_RES) {
        return $res;
    } elseif ($return === DB_RETURN_ROWCOUNT) {
        return $res ? mysqli_num_rows($res) : 0;
    } elseif ($return === DB_RETURN_ROW || $return === DB_RETURN_ROWS || $return === DB_RETURN_VALUE) {
        // Keyfields are only valid for DB_RETURN_ROWS.
        if ($return !== DB_RETURN_ROWS) {
            $keyfield = NULL;
        }
        $rows = array();
        if ($res) {
            while ($row = mysqli_fetch_row($res)) {
                if ($keyfield === NULL) {
                    $rows[] = $row;
                } else {
                    $rows[$row[$keyfield]] = $row;
                }
            }
        }
        // Return all rows.
        if ($return === DB_RETURN_ROWS) {
            /* Might be FALSE in case of ignored errors. */
            if (!is_bool($res)) {
                mysqli_free_result($res);
            }
            return $rows;
        }
        // Return a single row.
        if ($return === DB_RETURN_ROW) {
            if (count($rows) == 0) {
                return NULL;
            } else {
                return $rows[0];
            }
        }
        // Return a single value.
        if (count($rows) == 0) {
            return NULL;
        } else {
            return $rows[0][0];
        }
    } elseif ($return === DB_RETURN_ASSOC || $return === DB_RETURN_ASSOCS) {
        // Keyfields are only valid for DB_RETURN_ASSOCS.
        if ($return !== DB_RETURN_ASSOCS) {
            $keyfield = NULL;
        }
        $rows = array();
        if ($res) {
            while ($row = mysqli_fetch_assoc($res)) {
                if ($keyfield === NULL) {
                    $rows[] = $row;
                } else {
                    $rows[$row[$keyfield]] = $row;
                }
            }
        }
        // Return all rows.
        if ($return === DB_RETURN_ASSOCS) {
            /* Might be FALSE in case of ignored errors. */
            if (!is_bool($res)) {
                mysqli_free_result($res);
            }
            return $rows;
        }
        // Return a single row.
        if ($return === DB_RETURN_ASSOC) {
            if (count($rows) == 0) {
                return NULL;
            } else {
                return $rows[0];
            }
        }
    } elseif ($return === DB_RETURN_NEWID) {
        return mysqli_insert_id($conn);
    }
    trigger_error('Internal error: phorum_db_interact(): ' . 'illegal return type specified!', E_USER_ERROR);
}
コード例 #29
0
ファイル: mysqli.php プロジェクト: BackupTheBerlios/k4bb-svn
 function executeUpdate($stmt)
 {
     $result = @mysqli_real_query($this->link, $stmt);
     if ($result == FALSE) {
         trigger_error("Invalid query: " . mysqli_error($this->link), E_USER_ERROR);
     }
     $this->num_queries++;
     return FALSE;
 }
コード例 #30
-1
function mysqli_query_select_varchar_unbuffered($type, $len, $runs, $rows, $host, $user, $passwd, $db, $port, $socket, $flag_original_code)
{
    $errors = $times = array();
    foreach ($rows as $k => $num_rows) {
        foreach ($runs as $k => $run) {
            $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = microtime(true);
            do {
                if (!($link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx connect failure (original code = %s)", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no');
                    break 3;
                }
                if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx drop table failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                    break 3;
                }
                if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, label %s)", $type))) {
                    $errors[] = sprintf("%d rows: SELECT %s %dx create table failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                    break 3;
                }
                $label = '';
                for ($i = 0; $i < $len; $i++) {
                    $label .= chr(mt_rand(65, 90));
                }
                $label = mysqli_real_escape_string($link, $label);
                for ($i = 1; $i <= $num_rows; $i++) {
                    if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES ({$i}, '{$label}')")) {
                        $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code = %s): [%d] %s", $num_rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                        break 3;
                    }
                }
                for ($i = 0; $i < $run; $i++) {
                    $start = microtime(true);
                    mysqli_real_query($link, "SELECT id, label FROM test");
                    $res = mysqli_use_result($link);
                    $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x query()'] += microtime(true) - $start;
                    if (!$res) {
                        $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code = %s): [%d] %s", $rows, $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                        break 4;
                    }
                    $start = microtime(true);
                    while ($row = mysqli_fetch_assoc($res)) {
                    }
                    $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x fetch_assoc()'] += microtime(true) - $start;
                }
                mysqli_close($link);
            } while (false);
            $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = microtime(true) - $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'];
        }
    }
    return array($errors, $times);
}