寫了一個設定pdo DSN的方法想請大家看看_PHP教程

來源:互聯網
上載者:User
寫了一個設定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的主機格式可能有多種形式,說不定人家是一個資料集群呢?

[ ]


http://www.bkjia.com/PHPjc/632606.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632606.htmlTechArticle寫了一個設定pdo DSN的方法想請大家看看 ORACLE跟SQLITE 都只有資料庫主機,連資料庫名都沒有,我不知道怎麼設定。 發出來大家看看吧 priv...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.