Wrote a way to set up a PDO DSN. Want to see _php tutorial

Source: Internet
Author: User
Tags dsn
Wrote a way to set up a PDO DSN, and I want you to see

Oracle and SQLite have only the database host, not even the database name, I do not know how to set.
Give it to everybody. 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 code Oracle looked at the cn.php.net and changed it a bit.

[ ]

I'll answer that.




d8888d Huitie Content-------------------------------------------------------
I'm here to study [img]http://www.111cn.cn/bbs/images/smilies/default/lol.gif[/img]

d8888d Huitie Content-------------------------------------------------------
Why is there no one to answer?

d8888d Huitie Content-------------------------------------------------------
've seen

d8888d Huitie Content-------------------------------------------------------
All two of these databases are used in wood.

d8888d Huitie Content-------------------------------------------------------
Study, only look at the program thinking, do not look at what database

d8888d Huitie Content-------------------------------------------------------
Please consult 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
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
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 and the full Oracle client
Not yet, you can use the 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 host format may have a variety of forms, perhaps others are a data cluster it?

[ ]


http://www.bkjia.com/PHPjc/632606.html www.bkjia.com true http://www.bkjia.com/PHPjc/632606.html techarticle wrote a method to set up PDO DSN I would like to see the Oracle and SQLite only the database host, even the database name is not, I do not know how to set. Let's have a look. Priv ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.