I wrote a method for setting pdo DSN. Could you please check it out?
Both ORACLE and SQLITE only have database hosts and even database names. I don't know how to set them.
Let's see it. 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 = 'oss: 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 to ORACLE and check the modification on cn.php.net.
[]
Let me answer
D8888D reply content -------------------------------------------------------
I am here to learn [img] http://www.111cn.cn/bbs/images/smilies/default/lol.gif#/img]
D8888D reply content -------------------------------------------------------
Why? Why don't I reply'
D8888D reply content -------------------------------------------------------
Yes
D8888D reply content -------------------------------------------------------
Both databases have been used.
D8888D reply content -------------------------------------------------------
Let's take a look at the program logic, not the database.
D8888D reply content -------------------------------------------------------
Please refer to the relevant materials 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
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
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 the code cursade at hotmail dot com
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. There may be multiple host formats for El. Maybe someone else is a data cluster?
[]