⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_connect.php

📁 Professional PHP5 code for this book
💻 PHP
字号:
<?phprequire_once('DB.php'); $dsn = 'pgsql://postgres@localhost/mydb';$conn = DB::connect($dsn);if(DB::isError($conn)) {  //you would probably want to do something a bit more graceful here  print("Unable to connect to the database using the DSN $dsn");  die($conn->getMessage());}//get all results as an associative array$conn->setFetchMode(DB_FETCHMODE_ASSOC);  $sql = "SELECT * FROM mytable";$data =& $conn->getAll($sql); //returns all rows. Only use with small recordsets// Always check that $data is not an errorif (DB::isError($data)) {    print("Error trying to run the query $sql");    die ($data->getMessage());}var_dump($data);$conn->disconnect(); //close the connection?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -