天天看點

PHP知識點筆記顯示錯誤:PDOException could not find driver.phpExcel的使用需要使用到php的xmlreader和xmlwriter擴充php的define不能重複定義PHP如何擷取本地所有變量安裝php子產品可以這麼安裝mysql的字元編碼如何在PHP中初始化mysql的字元編碼?PHP的PDO擴充為什麼PDO的prepare不能打出最後的sql

是表示pdo沒有安裝對應資料庫的擴充,比如沒有安裝pdo_mysql

<a href="http://pecl.php.net/package/pdo_mysql">http://pecl.php.net/package/pdo_mysql</a>

下載下傳源碼

phpize

./configure --with-php-config=/usr/local/php/bin/php-config

./make

./make install 

如果你是使用yum安裝php

就直接使用yum install php-xml來進行安裝

比如:

1

2

3

4

5

6

7

<code>&lt;?php</code>

<code>define(</code><code>"test"</code><code>,</code><code>"11"</code><code>);</code>

<code>define(</code><code>"test"</code><code>,</code><code>"22"</code><code>);</code>

<code>echo</code> <code>test;</code>

<code> </code> 

<code>[yejianfeng@xen193v ~/handcode]$ php test.php</code>

<code>php notice:  constant test already defined in /home/yejianfeng/handcode/test.php on line 4</code>

<code>notice: constant test already defined in /home/yejianfeng/handcode/test.php on line 4</code>

<code>11</code>

$localvariables = compact(array_keys(get_defined_vars()));

php_pdo_shared=1 pecl install pdo_mysql

mysql一般預設的用戶端字元編碼為:latin1

mysql的字元編碼有幾種:

mysql&gt; show variables like "character_set_%";

+--------------------------+----------------------------+

| variable_name            | value                      |

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | latin1                     |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | latin1                     |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

其中資訊輸入路徑是

client - connection - server

資訊輸出路徑是

server - connection - result

輸入set names utf8是臨時設定client和connection的字元編碼

有兩種方法可以初始化設定:

<code>$pdo</code> <code>=</code><code>new</code> <code>pdo(</code><code>"mysql:host={$config['host']};dbname={$config['dbname']};port={$config['port']}"</code><code>,</code>

<code>    </code><code>$config</code><code>[</code><code>'user'</code><code>],</code><code>$config</code><code>[</code><code>'password'</code><code>],</code><code>array</code><code>(pdo::mysql_attr_init_command =&gt;</code><code>"set names utf8"</code><code>));</code>

<code>         </code><code>$config</code><code>[</code><code>'user'</code><code>],</code><code>$config</code><code>[</code><code>'password'</code><code>]);</code>

<code>     </code><code>$pdo</code><code>-&gt;</code><code>exec</code><code>(</code><code>'set names utf8'</code><code>);</code>

PHP知識點筆記顯示錯誤:PDOException could not find driver.phpExcel的使用需要使用到php的xmlreader和xmlwriter擴充php的define不能重複定義PHP如何擷取本地所有變量安裝php子產品可以這麼安裝mysql的字元編碼如何在PHP中初始化mysql的字元編碼?PHP的PDO擴充為什麼PDO的prepare不能打出最後的sql

使用php如果要使用pdo,你需要安裝的擴充除了pdo,還要各種資料庫的驅動,pdo擴充是定義了一系列接口,但是你不可以使用pdo擴充直接操作資料庫,需要安裝制定pdo驅動擴充

pdo擴充的說明:http://www.php.net/manual/en/intro.pdo.php

pdo擴充隻能在php 5.0之上使用(使用了php的oo屬性)

針對不同的資料庫的擴充有:

PHP知識點筆記顯示錯誤:PDOException could not find driver.phpExcel的使用需要使用到php的xmlreader和xmlwriter擴充php的define不能重複定義PHP如何擷取本地所有變量安裝php子產品可以這麼安裝mysql的字元編碼如何在PHP中初始化mysql的字元編碼?PHP的PDO擴充為什麼PDO的prepare不能打出最後的sql

使用pdo一直有一個郁悶的地方,就是使用prepare的時候想要将最後執行的sql打出來做log,發現沒有方法。。。

後來想了想,prepare是mysql的語句,那麼pdo的prepare和execute實際上是對mysql發送了幾次請求,prepare,set,execute

是以,如果要打出log,隻有自己拼sql了。。。