程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 寫了一個設置pdo DSN的方法想請大家看看

寫了一個設置pdo DSN的方法想請大家看看

編輯:關於PHP編程




寫了一個設置pdo DSN的方法想請大家看看

ORACLE跟SQLITE 都只有數據庫主機,連數據庫名都沒有,我不知道怎麼設置。
發出來大家看看吧 private function setDSN()

{

switch (strtoupper($this->datatype)){

case 'MYSQL':

$_DSN = 'mysql:host='.$this->hostname.';dbname='.$this->database.';port='.$this->hostport;

break;

case 'MSSQL':

case 'DB2':

$_DSN = 'dblib:host='.$this->hostname.':'.$this->hostport.';dbname='.$this->database;

break;

case 'ORACLE':

$_tns = "

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP )(HOST = $this->hostname)(PORT = $this->hostport))

)

(CONNECT_DATA =

(SERVICE_NAME = $this->database)

)

)";

$_DSN = 'oci:dbname='.$_tns;

break;

case 'SQLITE':

$_DSN = 'sqlite:'.$this->hostname;

break;

case 'PGSQL':

$_DSN = 'pgsql:host='.$this->hostname.'port='.$this->hostport.';dbname='.$this->database;

break;

case 'FIREBIRD':

$_DSN = 'firebird:dbname='.$this->hostname.':'.$this->database;

break;

case 'ODBC':

$_DSN = 'odbc:DSN='.$this->hostname.';UID='.$this->username.';PWD='.$this->password;

break;

}

return $_DSN;

}


復制代碼ORACLE 看了一下cn.php.net上的又修改了一下。

[ ]

我來回答




D8888D回貼內容-------------------------------------------------------
我是來學習的[img]http://www.111cn.cn/bbs/images/smilies/default/lol.gif[/img]

D8888D回貼內容-------------------------------------------------------
分少的原因?怎麼沒人回復呢`

D8888D回貼內容-------------------------------------------------------
見過

D8888D回貼內容-------------------------------------------------------
這兩個數據庫 都木用過

D8888D回貼內容-------------------------------------------------------
學習一下,只看程序思路,不看用啥數據庫

D8888D回貼內容-------------------------------------------------------
請查閱手冊上相關的資料
Example#1 PDO_SQLITE DSN examples

The following examples show PDO_SQLITE DSN for connecting to SQLite databases: sqlite:/opt/databases/mydb.sq3

sqlite::memory:

sqlite2:/opt/databases/mydb.sq2

sqlite2::memory:
復制代碼
cursade at hotmail dot com
2006-04-21 14:29
if oracle and oracle instant client has been installed,
without db in the same host

For UNIX/LINUX,set $LD_LIBRARY_PATH
appent your instant client path and client/lib path to it,

For windows set PATH like this

After set the path ,set TNS_ADMIN everioment ,point to
where tnsnames.ora located.

Then,you can use service name to connect to your Database

Test coding

$param = $_POST;

$db_username = "youusername";

$db_password = "yourpassword";

$db = "oci:dbname=yoursid";

$conn = new PDO($db,$db_username,$db_password);

$name = $param['module'];

$file = $param['file'];

$stmt = $conn->exec("INSERT INTO AL_MODULE (AL_MODULENAME, AL_MODULEFILE) VALUES ('$name', '$file')");



?>

復制代碼cursade at hotmail dot com
2006-04-20 17:43
If instant client has been installed but the full oracle client
not yet ,you can use pdo to connect to oracle database
like following coding:

$tns = "

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = yourip)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = orcl)

)

)

";

$db_username = "youname";

$db_password = "yourpassword";

try{

$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);

}catch(PDOException $e){

echo ($e->getMessage());

}

?>

復制代碼
1、SQLite不是數據主機,而是數據庫文件
2、ORACEL的主機格式可能有多種形式,說不定人家是一個數據集群呢?

[ ]


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved