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

search for in the

MySQLi_STMT> <mysqli::use_result
Last updated: Fri, 06 Nov 2009

view this page in

mysqli::warning_count

mysqli_warning_count

(PHP 5)

mysqli::warning_count -- mysqli_warning_count指定した接続の直近のクエリから発生した警告の数を返す

説明

オブジェクト指向型(プロパティ):

int $warning_count;

手続き型:

int mysqli_warning_count ( mysqli $link )

この接続の直近のクエリについて、発生した警告の数を返します。

注意: 警告の内容を取得するには、SQL コマンド SHOW WARNINGS [limit row_count] を使用します。

パラメータ

link

手続き型のみ: mysqli_connect() あるいは mysqli_init() が返すリンク ID。

返り値

警告の数を返します。警告がなかった場合はゼロを返します。

例1 オブジェクト指向型

<?php
$mysqli 
= new mysqli("localhost""my_user""my_password""world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$mysqli->query("CREATE TABLE myCity LIKE City");

/* ウェールズの珍しい地名です */
$query "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
        'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')"
;

$mysqli->query($query);

if (
$mysqli->warning_count) {
    if (
$result $mysqli->query("SHOW WARNINGS")) {
        
$row $result->fetch_row();
        
printf("%s (%d): %s\n"$row[0], $row[1], $row[2]);
        
$result->close();
    }
}

/* 接続を閉じます */
$mysqli->close();
?>

例2 手続き型

<?php
$link 
mysqli_connect("localhost""my_user""my_password""world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

mysqli_query($link"CREATE TABLE myCity LIKE City");

/* ウェールズの珍しい地名です */
$query "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
        'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')"
;

mysqli_query($link$query);

if (
mysqli_warning_count($link)) {
    if (
$result mysqli_query($link"SHOW WARNINGS")) {
        
$row mysqli_fetch_row($result);
        
printf("%s (%d): %s\n"$row[0], $row[1], $row[2]);
        
mysqli_free_result($result);
    }
}

/* 接続を閉じます */
mysqli_close($link);
?>

上の例の出力は以下となります。

Warning (1264): Data truncated for column 'Name' at row 1

参考

  • mysqli_errno() - 直近の関数コールによるエラーコードを返す
  • mysqli_error() - 直近のエラーの内容を文字列で返す
  • mysqli_sqlstate() - 直前の MySQL の操作での SQLSTATE エラーを返す



add a note add a note User Contributed Notes
mysqli::warning_count
There are no user contributed notes for this page.

MySQLi_STMT> <mysqli::use_result
Last updated: Fri, 06 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites