I wrote a method to set up pdo DSN and would like everyone to take a look
Both ORACLE and SQLITE only have the database host, not even the database name. I don't know how to set it up.
Send it out for everyone to take a look at 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;
}
Copy the code ORACLE and check it on cn.php.net and modify it.
[ ]
Let me answer
D8888D reply content------------------------------------------------- ----------
I’m here to learn [img]http://www.111cn.cn/bbs/images/smilies/default/lol.gif[/img]
D8888D reply content------------------------------------------------- ----------
The reason for the low score? Why no one responded`
D8888D reply content------------------------------------------------- ----------
Saw it
D8888D reply content------------------------------------------------- ----------
I have never used these two databases
D8888D reply content------------------------------------------------- ----------
Learn it, only look at the program ideas, not the database used
D8888D reply content------------------------------------------------- ----------
Please check the relevant information in the manual
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:
Copy code
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
append 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')");
?>
Copy code 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());
}
?>
Copy code
1. SQLite is not a data host, but a database file
2. ORACEL’s host format may have many forms. Maybe it is a data cluster?
[ ]