欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

  1. <legend id='t8q6tirk'><style id='dtbxefui'><dir id='rxh379y2'><q id='t0q4klol'></q></dir></style></legend>
    1. <small id='6gv89md9'></small><noframes id='06ikt766'>

      <i id='klylih2r'><tr id='9fm6jbrl'><dt id='od678b08'><q id='geiz7xai'><span id='vrgaq001'><b id='r2g900vt'><form id='l87p70fi'><ins id='1863kp3d'></ins><ul id='u3v6jq7i'></ul><sub id='v6fq3nsc'></sub></form><legend id='47j2xcks'></legend><bdo id='5vx5fke3'><pre id='a59evv3m'><center id='1uo3sidr'></center></pre></bdo></b><th id='3lxej25u'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='tu55x3s1'><tfoot id='04p56tih'></tfoot><dl id='9js3odbp'><fieldset id='bdbi4l4u'></fieldset></dl></div>

      • <bdo id='f9tqaxhm'></bdo><ul id='rfrcvy02'></ul>
    2. <tfoot id='ko5ehx9m'></tfoot>

      歡迎來到入門教程網(wǎng)!

      PHP編程

      當(dāng)前位置:主頁 > 網(wǎng)絡(luò)編程 > PHP編程 >

      網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子

      來源:本站原創(chuàng)|時(shí)間:2023-04-02|欄目:PHP編程|點(diǎn)擊: 次

      如何在WordPress中自定義PHP頁面并操作數(shù)據(jù)庫

      1. 嘗試設(shè)置一個(gè)頁面模板

      1)拷貝一個(gè)index.php并改名為其它名,如list.php;

      2)在list.php頁面最頂部添加

      ?php /*

      Template Name: 友鏈

      */

      ?

      以上兩步就可以創(chuàng)建一個(gè)頁面模板了,修改并保存好這個(gè)文件后,創(chuàng)建一個(gè)新頁面或者修改已存在的頁面。在右下邊有個(gè)“頁面模板”的面板,在下拉菜單中選中“友鏈”后保存就可以了。

      然后在頁面中添加任何內(nèi)容,包括html代碼就可以顯示了??墒俏业男枨笫且约和瓿蒔HP代碼獲取數(shù)據(jù)并展示,它不能這么做。

      2. 調(diào)用 WordPress 的 API實(shí)現(xiàn)URL正確跳轉(zhuǎn)

      這種方法的自由度較高,并且可以創(chuàng)建非WordPress格式的URL。比如我們要把 轉(zhuǎn)交給主題文件夾下的 /custom/list.php 來處理,就可以用這種方式來處理。這種方法用到 template redirect 鉤子,template redirect 是 WordPress 在預(yù)處理好所有參數(shù)設(shè)置之后決定調(diào)用主題模板的時(shí)候調(diào)用的。

      在functions.php模板函數(shù)文件中添加以下實(shí)例代碼:

      function loadCustomTemplate($template) {

      global $wp_query;

      if(!file_exists($template))return;

      $wp_query-is_page = true;

      $wp_query-is_single = false;

      $wp_query-is_home = false;

      $wp_query-comments = false;

      // if we have a 404 status

      if ($wp_query-is_404) {

      // set status of 404 to false

      unset($wp_query-query["error"]);

      $wp_query-query_vars["error"]="";

      $wp_query-is_404=false;

      }

      // change the header to 200 OK

      header("HTTP/1.1 200 OK");

      //load our template

      include($template);

      exit;

      }

      function templateRedirect() {

      $basename = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);

      loadCustomTemplate(TEMPLATEPATH.'/custom/'."/$basename.php");

      }

      add_action('template_redirect', 'templateRedirect');

      這樣就實(shí)現(xiàn)了 WordPress 查找 /custom 文件夾下的 php 文件,并且將相匹配的 URL 請(qǐng)求轉(zhuǎn)交給對(duì)應(yīng)的 php 文件來處理的效果,與此同時(shí),這個(gè) php 文件還保持了對(duì) WordPress API 的調(diào)用,因此留給我們的空間非常大。

      接下來就可以在 /custom 文件夾下自定義一個(gè)list.php文件然后通過鏈接訪問。

      3. 添加頁面內(nèi)容,獲取自定義數(shù)據(jù)庫/表中的內(nèi)容

      然后就可以根據(jù)需要自己需要來實(shí)現(xiàn)自己想要的功能,這里需要有以下幾點(diǎn)要處理:

      1)如何操作數(shù)據(jù)庫

      WordPress提供了一個(gè)全局變量$wpdb,并將其實(shí)例化為wpdb類的對(duì)象。這樣我們就可以直接使用$wpdb來調(diào)用所有的數(shù)據(jù)庫操作函數(shù)。通過這個(gè)$wpdb對(duì)象,我們可以對(duì)WordPress數(shù)據(jù)庫進(jìn)行任何操作,包括建表、查詢、刪除、更新等。使用$wpdb-get_results實(shí)現(xiàn)執(zhí)行sql語句操作數(shù)據(jù)庫,并獲取結(jié)果。

      global $wpdb;

      $sql= "SELECT * FROM ".$wpdb-prefix.table;

      $a = $wpdb-get_results($sql);

      2)使用wordpress的樣式

      通過F12查看首頁代碼就可以發(fā)現(xiàn)只要使用對(duì)應(yīng)的class樣式就能輕松讓頁面統(tǒng)一規(guī)整。那么就把對(duì)應(yīng)的html添加到自定義PHP頁面中即可。

      3)利用wordpress的規(guī)則輕松實(shí)現(xiàn)翻頁

      wordpress已經(jīng)默認(rèn)支持翻頁,格式如:,只要在自定義的頁面里面定義好每頁返回正確的內(nèi)容就好啦。

      4. 設(shè)置nginx rewrite規(guī)則

      可讀性強(qiáng)的URL一定不能是這樣的格式,對(duì)爬蟲也不友好,那就需要配置好rewrite規(guī)則,我使用的是nginx的配置為:

      rewrite ^(.*)/indexed/page/([0-9]+)$ $1/indexed?page=$2 last;

      到現(xiàn)在為止,離成功只有一步之遙了,那就是新建一個(gè)頁面, 大功告成!

      PHP操作mysql數(shù)據(jù)庫的步驟

      PHP訪問MySQL數(shù)據(jù)庫:

      因?yàn)檫B接數(shù)據(jù)庫需要較長(zhǎng)的時(shí)間和較大的資源開銷,所以如果在多個(gè)網(wǎng)頁中都要頻繁地訪問數(shù)據(jù)庫,則可以建立與數(shù)據(jù)庫的持續(xù)連接。即調(diào)用mysql_pconnect()代替mysql_connect()。

      基本步驟:

      1.連接服務(wù)器:mysql_connect();

      2.選擇數(shù)據(jù)庫:mysql_select_db();

      3.執(zhí)行SQL語句:mysql_query();

      查詢:select

      顯示:show

      插入:insert

      into

      更新:update

      刪除:delete

      4.關(guān)閉結(jié)果集:mysql_free_result($result);

      5.關(guān)閉數(shù)據(jù)庫:mysql_close($link);

      php中選擇打開數(shù)據(jù)庫的方法是

      在mysql數(shù)據(jù)庫中,創(chuàng)建一個(gè)test數(shù)據(jù)庫,用于測(cè)試。

      請(qǐng)點(diǎn)擊輸入圖片描述

      新建一個(gè)php文件,命名為test.php,用于講解php如何選擇要操作的數(shù)據(jù)庫。

      請(qǐng)點(diǎn)擊輸入圖片描述

      在test.php文件中,使用header()方法將頁面的編碼格式設(shè)置為utf-8,避免輸出中文亂碼。

      請(qǐng)點(diǎn)擊輸入圖片描述

      在test.php文件中,使用mysql_connect()函數(shù),通過賬號(hào)和密碼創(chuàng)建一個(gè)數(shù)據(jù)庫的連接。

      請(qǐng)點(diǎn)擊輸入圖片描述

      在test.php文件中,再使用mysql_select_db()函數(shù)選擇要操作的數(shù)據(jù)庫test,選擇數(shù)據(jù)庫成功,則返回true,否則,返回false。最后,通過if語句判斷結(jié)果。

      請(qǐng)點(diǎn)擊輸入圖片描述

      在瀏覽器打開test.php文件,查看結(jié)果。

      請(qǐng)點(diǎn)擊輸入圖片描述

      END

      總結(jié):

      1、創(chuàng)建一個(gè)test數(shù)據(jù)庫。

      2、使用mysql_connect()函數(shù)創(chuàng)建一個(gè)數(shù)據(jù)庫的連接。

      3、再使用mysql_select_db()函數(shù)選擇要操作的數(shù)據(jù)庫test,并通過if語句判斷結(jié)果。

      PHP網(wǎng)站怎么連接到數(shù)據(jù)庫?

      常規(guī)方式

      常規(guī)方式就是按部就班的讀取文件了。其余的話和上述方案一致。

      // 讀取配置文件內(nèi)容

      $handle = fopen("filepath", "r"); ? ? ? ? ? ?$content = fread($handle, filesize("filepath"));123

      PHP解析XML

      上述兩種讀取文件,其實(shí)都是為了PHP解析XML來做準(zhǔn)備的。關(guān)于PHP解析XML的方式的博客有很多。方式也有很多,像simplexml,XMLReader,DOM啦等等。但是對(duì)于比較小型的xml配置文件,simplexml就足夠了。

      配置文件

      ?xml version="1.0" encoding="UTF-8" ?mysql

      !-- 為防止出現(xiàn)意外,請(qǐng)按照此標(biāo)準(zhǔn)順序書寫.其實(shí)也無所謂了 --

      hostlocalhost/host

      userroot/user

      password123456/password

      dbtest/db

      port3306/port/mysql12345678910

      解析

      ?php/**

      * 作為解析XML配置文件必備工具

      */class XMLUtil {

      public static $dbconfigpath = "./db.config.xml"; ? ?public static function getDBConfiguration() {

      $dbconfig = array (); ? ? ? ?try { ? ? ? ? ? ?// 讀取配置文件內(nèi)容

      $handle = fopen(self::$dbconfigpath, "r"); ? ? ? ? ? ?$content = fread($handle, filesize(self::$dbconfigpath)); ? ? ? ? ? ?// 獲取xml文檔根節(jié)點(diǎn),進(jìn)而獲取相關(guān)的數(shù)據(jù)庫信息

      $mysql = simplexml_load_string($content); ? ? ? ? ? ?// 將獲取到的xml節(jié)點(diǎn)信息賦值給關(guān)聯(lián)數(shù)組,方便接下來的方法調(diào)用

      $dbconfig['host'] = $mysql-host; ? ? ? ? ? ?$dbconfig['user'] = $mysql-user; ? ? ? ? ? ?$dbconfig['password'] = $mysql-password; ? ? ? ? ? ?$dbconfig['db'] = $mysql-db; ? ? ? ? ? ?$dbconfig['port'] = $mysql-port; ? ? ? ? ? ?// 將配置信息以關(guān)聯(lián)數(shù)組的形式返回

      return $dbconfig;

      } catch ( Exception $e ) { ? ? ? ? ? ?throw new RuntimeException ( "mark讀取數(shù)據(jù)庫配置文件信息出錯(cuò)!/markbr /" );

      } ? ? ? ?return $dbconfig;

      }

      }1234567891011121314151617181920212223242526272829

      數(shù)據(jù)庫連接池

      對(duì)于PHP程序而言,優(yōu)化永無止境。而數(shù)據(jù)庫連接池就在一定程度上起到了優(yōu)化的作用。其使得對(duì)用戶的每一個(gè)請(qǐng)求而言,無需每次都像數(shù)據(jù)庫申請(qǐng)鏈接資源。而是通過已存在的數(shù)據(jù)庫連接池中的鏈接來返回,從時(shí)間上,效率上,都是一個(gè)大大的提升。

      于是,這里簡(jiǎn)單的模擬了一下數(shù)據(jù)庫連接池的實(shí)現(xiàn)。核心在于維護(hù)一個(gè)“池”。

      從池子中取,用畢,歸還給池子。

      ?php/**x

      * ?PHP中的數(shù)據(jù)庫 工具類設(shè)計(jì)

      * ?郭璞

      * ?2016年12月23日

      *

      **/class DbHelper { ? ?private $dbconfig; ? ?private $dbpool; ? ?public $poolsize; ? ?public function __construct($poolsize = 20) { ? ? ? ?if (! file_exists ( "./utils.php" )) { ? ? ? ? ? ?throw new RuntimeException ( "markutils.php文件丟失,無法進(jìn)行配置文件的初始化操作!/markbr /" );

      }else {

      require './utils.php';

      } ? ? ? ?// 初始化 配置文件信息

      $this-dbconfig = XMLUtil::getDBConfiguration (); ? ? ? ?// 準(zhǔn)備好數(shù)據(jù)庫連接池“偽隊(duì)列”

      $this-poolsize = $poolsize;

      $this-dbpool = array (); ? ? ? ?for($index = 1; $index = $this-poolsize; $index ++) {

      $conn = mysqli_connect ( $this-dbconfig ['host'], $this-dbconfig ['user'], $this-dbconfig ['password'], $this-dbconfig ['db'] ) or die ( "mark連接數(shù)據(jù)庫失敗!/markbr /" );

      array_push ( $this-dbpool, $conn );

      }

      } ? ?/**

      * 從數(shù)據(jù)庫連接池中獲取一個(gè)數(shù)據(jù)庫鏈接資源

      *

      * @throws ErrorException

      * @return mixed

      */

      public function getConn() { ? ? ? ?if (count ( $this-dbpool ) = 0) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫連接池中已無鏈接資源,請(qǐng)稍后重試!/mark" );

      } else { ? ? ? ? ? ?return array_pop ( $this-dbpool );

      }

      } ? ?/**

      * 將用完的數(shù)據(jù)庫鏈接資源放回到數(shù)據(jù)庫連接池

      *

      * @param unknown $conn

      * @throws ErrorException

      */

      public function release($conn) { ? ? ? ?if (count ( $this-dbpool ) = $this-poolsize) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫連接池已滿/markbr /" );

      } else {

      array_push ( $this-dbpool, $conn );

      }

      }

      }

      <small id='h9tex2fi'></small><noframes id='32umhcga'>

      <tfoot id='4d8lg4ae'></tfoot>

        <tbody id='8cm13i1w'></tbody>
              <i id='0h44gghl'><tr id='w8fp9ae5'><dt id='vlmpw259'><q id='56ej3d74'><span id='8rm590jv'><b id='f024qczg'><form id='01j1s5qa'><ins id='f8w3zq2g'></ins><ul id='eo4evm5h'></ul><sub id='7g18em02'></sub></form><legend id='b5m56vxw'></legend><bdo id='qpki2d54'><pre id='k46kl6ii'><center id='lipx2wmj'></center></pre></bdo></b><th id='rt5m4l9v'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='ps1m6e3i'><tfoot id='1y31fsvf'></tfoot><dl id='ub2nuhs4'><fieldset id='68n6ra9v'></fieldset></dl></div>

            1. <legend id='w5w6fx22'><style id='15o9xvvl'><dir id='h08fa664'><q id='8sgsokxl'></q></dir></style></legend>
                <bdo id='1jt5mzh3'></bdo><ul id='vxukhaac'></ul>

                網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

                如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

                聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

                Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有

              • <legend id='bc77ivkm'><style id='3fzu9z10'><dir id='ej4pcmvf'><q id='o0wxhd25'></q></dir></style></legend>

                • <bdo id='vtkl0r0d'></bdo><ul id='mzh9fesj'></ul>

                  1. <i id='njroxzce'><tr id='zoiy29sq'><dt id='6xt6y7hy'><q id='xvb57ajt'><span id='2c5pydzh'><b id='wwqeyzdc'><form id='5e1n5rl0'><ins id='h5qatvyu'></ins><ul id='729fn7h3'></ul><sub id='vaaxaiq8'></sub></form><legend id='yffvwy74'></legend><bdo id='ciscc8h4'><pre id='1g1jg07t'><center id='udxzr7x7'></center></pre></bdo></b><th id='jmn32n4r'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='2gpq8vwx'><tfoot id='596snrv4'></tfoot><dl id='smexv5n7'><fieldset id='40kw4cpv'></fieldset></dl></div>

                    <small id='mhsb8rki'></small><noframes id='ksnv21e6'>

                    <tfoot id='k3v62g7l'></tfoot>