歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 簡單介紹下PHP5中引入的MySQLI

簡單介紹下PHP5中引入的MySQLI

日期:2017/2/27 9:26:50   编辑:更多Linux
  mysqli.dll是PHP對mysql新特性的一個擴展支持。在PHP5中可以在php.ini中加載,如下圖:    interface, ingenious, incompatible or incomplete(改擴展仍在開發中,因為MYSQL4。1和MYSQL5都沒有正式推出尚在開發中,新的特性沒有完全實現)    mysqli想實現的目標具體有:    -更簡單的維護    -更好的兼容性    -向後兼容    mysql(指PHP中的模塊)發展到現在顯得比較凌亂,有必要重新做下整理。同時,有必要跟上MYSQL(DBMS)的發展步伐,加入新的特性的支持,以及適應MYSQL(DBMS)以後的版本。所以誕生了mysqli.dll    mysqli.dll的特性:    -可以和mysql.dll一樣的方式使用    -支持OO接口,簡簡單單調用    -支持MYSQL4。1引入的新特性    -通過mysqli_init() 等相關函數,可以設置高級連接選項    mysqli的使用例子:    1.和以前mysql.dll一樣的方法:    <?php    /* Connect to a MySQL server */    $link = mysqli_connect(    'localhost', /* The host to connect to */    'user', /* The user to connect as */    'passWord', /* The password to use */    'world'); /* The default table to query */    if (!$link) {    printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error());    exit;    }    /* Send a query to the server */    if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {    print("Very large cities are:n");    /* Fetch the results of the query */    while( $row = mysqli_fetch_assoc($result) ){    printf("%s (%s)n", $row['Name'], $row['Population']);    }    /* Destroy the result set and free the memory used for it */    mysqli_free_result($result);    }    /* Close the connection */    mysqli_close($link);    ?>    輸出結果:    Very large cities are:    Mumbai (Bombay) (10500000)    Seoul (9981619)    São Paulo (9968485)    Shanghai (9696300)    Jakarta (9604900)    2.使用內置OO接口方式調用:    <?php    /* Connect to a MySQL server */    $mysqli = new mysqli('localhost', 'user', 'password', 'world');    if (mysqli_connect_errno()) {    printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error());    exit;    }    /* Send a query to the server */    if ($result = $mysqli->query('SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {    print("Very large cities are:n");    /* Fetch the results of the query */    while( $row = $result->fetch_assoc() ){    printf("%s (%s)n", $row['Name'], $row['Population']);    }    /* Destroy the result set and free the memory used for it */    $result->close();    }    /* Close the connection */    $mysqli->close();    ?>    支持的新特性還有:Bound Parameters,Bound Results等。。。




Copyright © Linux教程網 All Rights Reserved