I wrote a method for setting pdoDSN. please take a look. I wrote a method to set pdoDSN. I want to see that ORACLE and SQLITE only have Database hosts and even Database names. I don't know how to set them. Let's take a look. priv has written a method for setting pdo DSN. please take a look.
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;
}
ORACLE looked at cn.php.net and modified it again.
[]
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:
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 ')");
?>
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 ());
}
?>
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?
[]
The mongodsn method can be used to check whether ORACLE and SQLITE only have Database hosts and even Database names. I don't know how to set them. Let's take a look at priv...