解析在PHP中使用mysqli擴(kuò)展庫(kù)對(duì)mysql的操作_PHP教程
推薦:淺析PHP繪圖技術(shù)1、圖片格式:目前網(wǎng)站開發(fā)常見的圖片格式有g(shù)if,jpg/jpeg,png ..... 區(qū)別: gif 圖片壓縮率高,但是只能顯示256色,可能造成顏色的丟失,可以顯示動(dòng)畫 jpg/jpeg 圖片壓縮率高(有損壓縮),可以用較小的文件來(lái)顯示,網(wǎng)頁(yè)上用得比較多 png 該格式綜合了gif和jpg的優(yōu)勢(shì),缺
本篇文章是對(duì)在PHP中使用mysqli擴(kuò)展庫(kù)對(duì)mysql的操作進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下1、在PHP中 使用mysqli擴(kuò)展庫(kù)對(duì)mysql 的dql操作
<?php
header("Content-type: text/html;charset=utf-8");
//mysqli操作mysql數(shù)據(jù)庫(kù)(面向?qū)ο蠓绞?
//1、創(chuàng)建MySQLi對(duì)象
$mysqli =new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("連接失敗".$mysqli->connect_error);
}
//2、操作數(shù)據(jù)庫(kù)(發(fā)送sql)
$sql="select *from user1";
//3、處理結(jié)果
$res =$mysqli->query($sql);
//var_dump($res);
//fetch_assoc \fetch_array \fetch_object
while($row=$res->fetch_row()){
var_dump($row);
/* foreach($row as $val){
echo '--'.$val;
}
echo '<br/>';*/
}
//4、關(guān)閉資源
$res->free();
$mysqli->close();
?>
下面是面向過程的
<?php
header("Content-type: text/html;charset=utf-8");
$mysqli=mysqli_connect("localhost","root","root","test");
if(!$mysqli){
die("連接失敗".mysqli_connect_error());
}
$sql="select *from user1";
$res=mysqli_query($mysqli,$sql);
//var_dump($res);
while($row=mysqli_fetch_row($res)){
foreach ($row as $val){
echo '-'.$val;
}
echo '<br/>';
}
//釋放內(nèi)存
mysqli_free_result($res);
mysqli_close($mysqli);
?>
2、在PHP中 使用mysqli擴(kuò)展庫(kù)對(duì)mysql 的dml操作
<?php
//使用mysqli 擴(kuò)展庫(kù)對(duì)mysql的crud 操作
header("Content-type: text/html;charset=utf-8");
$mysqli = new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("連接失敗".$mysql->connect_error);
}
//增加一條記錄
//$sql="insert into user1 (name,password,email,age) values ('lucy',md5('lucy'),'[email protected]',17)";
//刪除一條記錄
//$sql="delete from user1 where id =80";
//更新一條記錄
$sql="update user1 set age=20 where id=7";
$res=$mysqli->query($sql);
if(!$res){
echo "操作失敗".$mysqli->error;
}else{
if($mysqli->affected_rows>0){
echo "成功";
}else{
echo "沒有行受影響";
}
}
//關(guān)閉資源
$mysqli->close();
?>
3、進(jìn)行封裝
<?
class SqlHelper{
private $mysqli;
//這里先寫死,以后寫死的東西用一個(gè)文件來(lái)配置
private static $host="localhost";
private static $user="root";
private static $pwd="root";
private static $db="test";
public function __construct(){
$this->mysqli=new MySQLi(self::$host,self::$user,self::$pwd,self::$db);
if($this->mysqli->connect_error){
die("連接失敗".$this->mysqli->connect_error);
}
//設(shè)置字符集
$this->mysqli->query("set names utf8");
}
//dql operate
function execute_dql($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
return $res;
}
//dml operate
function execute_dml($sql){
$res =$this->mysqli->query($sql) or die($this->mysqli->error);
if(!$res){
return 0;//失敗
}else{
if($this->mysqli->affected_rows>0){
return 1;//成功
}else{
return 2;//沒有行到影響
}
}
}
}
?>
分享:解決FastCGI 進(jìn)程超過了配置的活動(dòng)超時(shí)時(shí)限的問題近日,需要滿足測(cè)試需求,進(jìn)行大數(shù)據(jù)并發(fā)測(cè)試時(shí),報(bào)出【 HTTP 錯(cuò)誤 500.0 - Internal Server Error E:\PHP\php-cgi.exe - FastCGI 進(jìn)程超過了配置的活動(dòng)超時(shí)時(shí)限 】 解決辦法: IIS7-FastCGI設(shè)置-雙擊php-cgi.exe-活動(dòng)超時(shí) 項(xiàng)默認(rèn)是設(shè)置為70(秒),改為600(10分鐘,此處
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- Apache二級(jí)域名實(shí)現(xiàn)方法介紹
- php程序調(diào)試方法總結(jié)
- 基于Zend的Config機(jī)制的應(yīng)用分析
- PHP中常用的幾個(gè) mysql 語(yǔ)句
- 用php實(shí)現(xiàn)簡(jiǎn)單的滑動(dòng)菜單
- 怎樣得到一個(gè)字符串的最后一個(gè)字符
- php4和php5單態(tài)模式(Singleton Pattern)寫法
- PHP筆記之:基于面向?qū)ο笤O(shè)計(jì)的詳解
- php環(huán)境搭建:PHPnow綠色PHP環(huán)境包
- 初學(xué):在PHP開發(fā)中如何使用Session?
- 相關(guān)鏈接:
- 教程說明:
PHP教程-解析在PHP中使用mysqli擴(kuò)展庫(kù)對(duì)mysql的操作
。