写了一个设置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的主机格式可能有多种形式,说不定人家是一个数据集群呢?
[ ]

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
