CODEFETCH™
            Examples
Searched for 4 expression(s): connect   form   database   select  
PHP API
db2_connect search codefetch
Returns a connection to a database
db2_pconnect search codefetch
Returns a persistent connection to a database
dbx_connect search codefetch
Open a connection/database
fbsql_database search codefetch
Get or set the database name used with a connection
fbsql_select_db search codefetch
Select a FrontBase database
Most relevant API matches shown. View All.
Source code below from:
Beginning PHP and MySQL 5: From Novice to Professional, Second Edition (Beginning: from Novice to Professional)
By W. Jason Gilmore
Published 23 January, 2006
Average rating

      Powells     Alibris

1590595521/ch20/listing20-8.php (34 lines)
4    // Function: getRandQuote() 
5    // Inputs: None 
6    // Outputs: A string containing information about a quote, 
7    //  its attribution, and date. 
8    function getRandQuote() { 
9      // Connect to the MySQL DB server and select the database
10       mysql_connect("localhost","webserviceuser","secret");
11       mysql_select_db("chapter20");
Additional matches viewable in cache of 1590595521/ch20/listing20-8.php.
1590595521/ch29/listing29-2.php (34 lines)
6  
7       // Connect to the server and select the database
8       $linkID = @mysql_connect("localhost","webuser","secret") 
9                 or die("Could not connect to MySQL server");
10       @mysql_select_db("company") or die("Could not select database");
11  
12       // Retrieve the posted product information.
13       $productid = $_POST['productid']; 
14       $name = $_POST['name']; 
Additional matches viewable in cache of 1590595521/ch29/listing29-2.php.
1590595521/ch35/listing35-1.php (40 lines)
1 <p> 
2 Search the employee database:<br />
3 <form action="simplesearch.php" method="post">
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 <?php 11 12 // If the form has been submitted with a supplied last name 13 if (isset($_POST['lastname'])) { 14 15 // Connect to server and select database 16 17 $mysqldb = new mysqli("localhost","websiteuser","secret","corporate");
Additional matches viewable in cache of 1590595521/ch35/listing35-1.php.
1590595521/ch35/listing35-2.php (44 lines)
1 <p> 
2 Search the employee database:<br />
3 <form action="searchextended.php" method="post">
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 16 <?php 17 // If the form has been submitted with a supplied keyword 18 if (isset($_POST['field'])) { 19 20 // Connect to server and select database 21 $mysqldb = new mysqli("localhost","websiteuser","secret","corporate"); 22
Additional matches viewable in cache of 1590595521/ch35/listing35-2.php.
1590595521/ch35/listing35-3.php (33 lines)
1 <p> 
2 Search the online resources database:<br />
3 <form action="fulltextsearch.php" method="post">
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 <?php 11 12 // If the form has been submitted with supplied keywords 13 if (isset($_POST['keywords'])) { 14 15 // Connect to server and select database 16 $mysqldb = new mysqli("localhost","root","jason","corporate"); 17
Additional matches viewable in cache of 1590595521/ch35/listing35-3.php.
Source code below from:
Foundation PHP for Dreamweaver 8
By David Powers
Published 19 December, 2005
Average rating

      Powells     Alibris

FdnPHPforDW8/site_check/ch11/list_blog_03.php (47 lines)
1 <?php require_once('../Connections/seasonAdmin.php'); ?>
2 <?php 
3 mysql_select_db($database_seasonAdmin, $seasonAdmin);
4 $query_getArticles = "SELECT article_id, title, DATE_FORMAT(created, '%b %e, %Y') AS created, image, caption FROM blog ORDER BY created DESC";
5 $getArticles = mysql_query($query_getArticles, $seasonAdmin) or die(mysql_error()); 
6 $row_getArticles = mysql_fetch_assoc($getArticles); 

FdnPHPforDW8/site_check/ch11/list_blog_04.php (48 lines)
1 <?php require_once('../Connections/seasonAdmin.php'); ?>
2 <?php 
3 mysql_select_db($database_seasonAdmin, $seasonAdmin);
4 $query_getArticles = "SELECT article_id, title, DATE_FORMAT(created, '%b %e, %Y') AS created, image, caption FROM blog ORDER BY created DESC";
5 $getArticles = mysql_query($query_getArticles, $seasonAdmin) or die(mysql_error()); 
6 $row_getArticles = mysql_fetch_assoc($getArticles); 

FdnPHPforDW8/site_check/ch11/blog_detail_01.php (46 lines)
1 <?php require_once('Connections/seasonQuery.php'); ?>
2 <?php 
3 $var1_getArticle = "-1"; 
4 if (isset($_GET['article_id'])) { 
5   $var1_getArticle = (get_magic_quotes_gpc()) ? $_GET['article_id'] : addslashes($_GET['article_id']); 
6 } 
7 mysql_select_db($database_seasonQuery, $seasonQuery);
8 $query_getArticle = sprintf("SELECT blog.article_id, blog.title, blog.article, DATE_FORMAT(blog.created, '%%b %%e, %%Y') AS theDate, DATE_FORMAT(blog.updated, '%%l.%%i %%p on %%b %%e, %%Y') as latest, blog.updated, blog.created, blog.image, blog.caption FROM blog WHERE blog.article_id = %s", $var1_getArticle);
9 $getArticle = mysql_query($query_getArticle, $seasonQuery) or die(mysql_error()); 
10 $row_getArticle = mysql_fetch_assoc($getArticle); 

FdnPHPforDW8/site_check/ch11/blog_detail_02.php (56 lines)
1 <?php require_once('Connections/seasonQuery.php'); ?>
2 <?php 
3 $var1_getArticle = "-1"; 
4 if (isset($_GET['article_id'])) { 
5   $var1_getArticle = (get_magic_quotes_gpc()) ? $_GET['article_id'] : addslashes($_GET['article_id']); 
6 } 
7 mysql_select_db($database_seasonQuery, $seasonQuery);
8 $query_getArticle = sprintf("SELECT blog.article_id, blog.title, blog.article, DATE_FORMAT(blog.created, '%%b %%e, %%Y') AS theDate, DATE_FORMAT(blog.updated, '%%l.%%i %%p on %%b %%e, %%Y') as latest, blog.updated, blog.created, blog.image, blog.caption FROM blog WHERE blog.article_id = %s", $var1_getArticle);
9 $getArticle = mysql_query($query_getArticle, $seasonQuery) or die(mysql_error()); 
10 $row_getArticle = mysql_fetch_assoc($getArticle); 

FdnPHPforDW8/site_check/ch11/blog_detail_03.php (56 lines)
1 <?php require_once('Connections/seasonQuery.php'); ?>
2 <?php 
3 $var1_getArticle = "-1"; 
4 if (isset($_GET['article_id'])) { 
5   $var1_getArticle = (get_magic_quotes_gpc()) ? $_GET['article_id'] : addslashes($_GET['article_id']); 
6 } 
7 mysql_select_db($database_seasonQuery, $seasonQuery);
8 $query_getArticle = sprintf("SELECT blog.article_id, blog.title, blog.article, DATE_FORMAT(blog.created, '%%b %%e, %%Y') AS theDate, DATE_FORMAT(blog.updated, '%%l.%%i %%p on %%b %%e, %%Y') as latest, blog.updated, blog.created, blog.image, blog.caption FROM blog WHERE blog.article_id = %s", $var1_getArticle);
9 $getArticle = mysql_query($query_getArticle, $seasonQuery) or die(mysql_error()); 
10 $row_getArticle = mysql_fetch_assoc($getArticle); 
Source code below from:
PHP Phrasebook (Developer's Library)
By Christian Wenz
Published 26 September, 2005
Average rating

      Powells     Alibris

ch07-database/mssql_query.php (33 lines)
2 <html> 
3 <head> 
4   <title>Databases</title>
5 </head> 
6 <body> 
7 <?php 
8   if (isset($_POST['quote']) && isset($_POST['author']) && 
9       isset($_POST['year']) && is_numeric($_POST['year'])) { 
10     if ($db = @mssql_connect('localhost', 'user', 'password')) {
11       require_once 'stripFormSlashes.inc.php';
12       mssql_select_db('phrasebook', $db);
13       ini_set('magic_quotes_sybase', 'On'); 
14       mssql_query(sprintf( 
Additional matches viewable in cache of ch07-database/mssql_query.php.
ch07-database/mysql_query.php (32 lines)
2 <html> 
3 <head> 
4   <title>Databases</title>
5 </head> 
6 <body> 
7 <?php 
8   if (isset($_POST['quote']) && isset($_POST['author']) && 
9       isset($_POST['year']) && is_numeric($_POST['year'])) { 
10     if ($db = @mysql_connect('localhost', 'user', 'password')) {
11       require_once 'stripFormSlashes.inc.php';
12       mysql_select_db('phrasebook', $db);
13       mysql_query(sprintf( 
14         'INSERT INTO quotes (quote, author, year) VALUES (\'%s\', \'%s\', \'%s\')', 
Additional matches viewable in cache of ch07-database/mysql_query.php.
ch07-database/mysqli_query.php (32 lines)
2 <html> 
3 <head> 
4   <title>Databases</title>
5 </head> 
6 <body> 
7 <?php 
8   if (isset($_POST['quote']) && isset($_POST['author']) && 
9       isset($_POST['year']) && is_numeric($_POST['year'])) { 
10     if ($db = @mysqli_connect('localhost', 'user', 'password')) {
11       require_once 'stripFormSlashes.inc.php';
12       mysqli_select_db($db, 'phrasebook');
13       mysqli_query($db, sprintf( 
14         'INSERT INTO quotes (quote, author, year) VALUES (\'%s\', \'%s\', \'%s\')', 
Additional matches viewable in cache of ch07-database/mysqli_query.php.
ch07-database/mysqli_stmt_execute.php (36 lines)
2 <html> 
3 <head> 
4   <title>Databases</title>
5 </head> 
6 <body> 
7 <?php 
8   if (isset($_POST['quote']) && isset($_POST['author']) && 
9       isset($_POST['year']) && is_numeric($_POST['year'])) { 
10     if ($db = @mysqli_connect('localhost', 'user', 'password')) {
11       require_once 'stripFormSlashes.inc.php';
12       mysqli_select_db($db, 'phrasebook');
13       $stmt = mysqli_prepare($db, 'INSERT INTO quotes (quote, author, year) VALUES (?, ?, ?)'); 
14       $quote = mysqli_real_escape_string($db, $_POST['quote']); 
Additional matches viewable in cache of ch07-database/mysqli_stmt_execute.php.
Source code below from:
Pro PHP Security (Pro)
By Chris Snyder and Michael Southwell
Published 29 August, 2005
Average rating

      Powells     Alibris

CHAPTER06/passwordHashingDemo.php (95 lines)
2  
3 function makeDBConnection() {
4   $connection = mysql_connect( 'localhost', 'username', 'password' );
5   if ( !$connection ) exit( "can't connect!" );
6   if ( !mysql_select_db( 'users', $connection ) ) exit( "can't select database!" );
7 } 
8  
9 function dbSafe( $value ) { 
10   return '"' . mysql_real_escape_string( $value ) . '"'; 
11 } 
12  
13 //////////////////////////////////// 
14 // deal with the new user's password 
15 //////////////////////////////////// 
16  
17 // capture the new user's information, submitted from the login form
18 $userName = $_POST['userName']; 
19 $userPassword = $_POST['userPassword']; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67 ////////////////////////////////////////// 68 69 // capture the returning user's information, submitted from the login form 70 $userName = $_POST['userName']; 71 $userPassword = $_POST['userPassword']; 72 73 // retrieve the stored password and salt for this user 74 makeDBConnection(); 75 $query = 'SELECT * FROM LOGIN WHERE username=' . dbSafe( $userName ); 76 77 $result = mysql_query( $query ); 78 if ( !$result ) exit( "$userName wasn't found in the database!" ); 79 80 $row = mysql_fetch_array( $result );
Additional matches viewable in cache of CHAPTER06/passwordHashingDemo.php.
Source code below from:
Foundation PHP 5 for Flash (Foundation)
By David Powers
Published 01 March, 2005
Average rating

      Powells     Alibris

php files/Ch12/edit_auth_pub.php (134 lines)
2 require_once('admin_funcs.php'); 
3 // include Database classes
4 require_once('../classes/database.php');
5 if ($_GET && !$_POST) { 
6   // get details of record to be edited 
7   $db=new Database('localhost','flashuser','deepthought','bookstore',0);
8   $getDets = 'SELECT * FROM '.$_GET['table'];
9   $getDets .= ' WHERE '.$_GET['type'].' = '.$_GET['num']; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 } 21 // create Database instance 22 $db=new Database('localhost','flashadmin','fortytwo','bookstore',0); 23 // if the "Update author name" button has been clicked
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 $author_id = $_POST['author_id']; 29 $checkName = "SELECT * FROM authors 30 WHERE first_name = '$first_name'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 $pub_id = $_POST['pub_id']; 54 $checkName = "SELECT * FROM publishers 55 WHERE publisher = '$publisher'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 } 71 // close database connection 72 $db->close();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 ?> 90 <form name="authorDets" id="authorDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 91 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110 </table> 111 </form> 112 <h1>Edit publisher</h1>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 ?> 117 <form name="publisherDets" id="publisherDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 118 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130 </table> 131 </form> 132 </div>

php files/Ch12/edit_auth_pub01.php (113 lines)
3 if ($_POST) { 
4   // include Database classes
5   require_once('../classes/database.php');
6   // escape quotes and apostrophes if magic_quotes_gpc off 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 } 13 // create Database instance 14 $db=new Database('localhost','flashadmin','fortytwo','bookstore',0); 15 // if the "Insert new author" button has been clicked
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 $family_name = $_POST['family_name']; 20 $checkName = "SELECT * FROM authors 21 WHERE first_name = '$first_name'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 $publisher = $_POST['publisher']; 42 $checkName = "SELECT * FROM publishers 43 WHERE publisher = '$publisher'";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 } 59 // close database connection 60 $db->close();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 ?> 78 <form name="authorDets" id="authorDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 79 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 </table> 93 </form> 94 <h1>Insert new publisher</h1>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98 ?> 99 <form name="publisherDets" id="publisherDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 100 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109 </table> 110 </form> 111 </div>

php files/Ch12/edit_auth_pub02.php (134 lines)
2 require_once('admin_funcs.php'); 
3 // include Database classes
4 require_once('../classes/database.php');
5 if ($_GET && !$_POST) { 
6   // get details of record to be edited 
7   $db=new Database('localhost','flashuser','deepthought','bookstore',0);
8   $getDets = 'SELECT * FROM '.$_GET['table'];
9   $getDets .= ' WHERE '.$_GET['type'].' = '.$_GET['num']; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 } 21 // create Database instance 22 $db=new Database('localhost','flashadmin','fortytwo','bookstore',0); 23 // if the "Update author name" button has been clicked
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 $author_id = $_POST['author_id']; 29 $checkName = "SELECT * FROM authors 30 WHERE first_name = '$first_name'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 $pub_id = $_POST['pub_id']; 54 $checkName = "SELECT * FROM publishers 55 WHERE publisher = '$publisher'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 } 71 // close database connection 72 $db->close();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 ?> 90 <form name="authorDets" id="authorDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 91 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110 </table> 111 </form> 112 <h1>Edit publisher</h1>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 ?> 117 <form name="publisherDets" id="publisherDets" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 118 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130 </table> 131 </form> 132 </div>

php files/Ch12/editbook.php (233 lines)
2 require_once('admin_funcs.php'); 
3 require_once('../classes/database.php');
4 // this code always runs, and gets lists of authors and publishers 
5 $db=new Database('localhost','flashuser','deepthought','bookstore',0);
6 $getAuthors = 'SELECT author_id,
7                CONCAT(first_name," ", UPPER(family_name)) AS author 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 $authors = $db->query($getAuthors); 11 $getPublishers = 'SELECT * FROM publishers ORDER BY publisher'; 12 $publishers = $db->query($getPublishers);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 // get details of book from the books table 18 $getDets = "SELECT title,isbn,pub_id,image,description 19 FROM books WHERE book_id = $book_id";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 // get list of authors from lookup table 30 $getAuthors = "SELECT author_id FROM book_to_author 31 WHERE book_id = $book_id";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 } 38 // this block runs only if the form has been submitted 39 if ($_POST && array_key_exists('updateBook',$_POST)) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 } 49 // if no publisher selected, value is 0, considered empty by PHP 50 elseif ($key == 'publisher') { 51 $error[] = 'You must select a publisher'; 52 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 if ($_POST['author'][0] == 'choose' && count($_POST['author']) < 2) { 67 $error[] = 'Select at least one author, or choose "Not listed"'; 68 } 69 // if all fields correctly filled, prepare to insert in database 70 if (!isset($error)) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 } 81 // create a Database instance, and set error reporting to plain text 82 $db = new Database('localhost','flashadmin','fortytwo','bookstore',0); 83 // first check that the same ISBN doesn't already exist 84 $checkISBN = 'SELECT isbn FROM books WHERE isbn = "'.$_POST['isbn'].'" 85 AND book_id != '.$_POST['book_id'];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 if ($result->num_rows > 0) { 88 $error[] = 'A book with that ISBN already exists in the database'; 89 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 $result = $db->query($update); 101 // if "Select author(s)" still selected, remove it from the array 102 if ($_POST['author'][0] == 'select') array_shift($_POST['author']); 103 if (in_array('other',$_POST['author'])) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150 ?> 151 <form name="bookDets" id="bookDets" method="post" action=""> 152 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
164 <th class="leftLabel">Author(s):</th> 165 <td><select name="author[]" size="6" multiple="multiple" id="author"> 166 <option value="choose"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168 if (isset($_POST['author']) && in_array('choose',$_POST['author'])) { 169 echo 'selected="selected"'; } ?> 170 >Select author(s)</option> 171 <option value="other" 172 <?php if (isset($authorList) && in_array(0,$authorList) || (isset($_POST['author']) && $_POST['author'] == 'other')) 173 echo 'selected="selected"'; ?> 174 >Not listed</option>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177 if ((isset($authorList) && in_array($row['author_id'],$authorList)) || (isset($_POST['author']) && in_array($row['author_id'], $_POST['author']))) { 178 echo 'selected="selected"'; 179 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 ?> 183 </select></td> 184 </tr>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 <th class="leftLabel">Publisher:</th> 187 <td><select name="publisher" id="publisher"> 188 <option value="0" 189 <?php if (isset($_POST['publisher']) && $_POST['publisher'] == '0') 190 echo 'selected="selected"';?>>Select publisher</option> 191 <option value="other" 192 <?php 193 if (isset($pub_id) && $pub_id == 0 || (isset($_POST['publisher']) && $_POST['publisher'] == 'other')) echo 'selected="selected"'; ?> 194 >Not listed</option>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
198 if ((isset($pub_id) && $pub_id == $row['pub_id']) || (isset($_POST['publisher']) && $_POST['publisher'] == $row['pub_id'])) 199 echo 'selected="selected"'; 200 echo '>'.$row['publisher'].'</option>'; 201 } 202 // close database connection 203 $db->close(); 204 ?> 205 </select></td> 206 </tr>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 </table> 230 </form> 231 </div>

php files/Ch12/editbook01.php (202 lines)
2 require_once('admin_funcs.php'); 
3 require_once('../classes/database.php');
4 // this code always runs, and gets lists of authors and publishers 
5 $db=new Database('localhost','flashuser','deepthought','bookstore',0);
6 $getAuthors = 'SELECT author_id,
7                CONCAT(first_name," ", UPPER(family_name)) AS author 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 $authors = $db->query($getAuthors); 11 $getPublishers = 'SELECT * FROM publishers ORDER BY publisher'; 12 $publishers = $db->query($getPublishers); 13 // this first block runs only if the form has been submitted 14 if ($_POST) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 } 24 // if no publisher selected, value is 0, considered empty by PHP 25 elseif ($key == 'publisher') { 26 $error[] = 'You must select a publisher'; 27 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 if ($_POST['author'][0] == 'choose' && count($_POST['author']) < 2) { 42 $error[] = 'Select at least one author, or choose "Not listed"'; 43 } 44 // if all fields correctly filled, prepare to insert in database 45 if (!isset($error)) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 } 56 // create a Database instance, and set error reporting to plain text 57 $db = new Database('localhost','flashadmin','fortytwo','bookstore',0); 58 // first check that the same ISBN doesn't already exist 59 $checkISBN = 'SELECT isbn FROM books 60 WHERE isbn = "'.$_POST['isbn'].'"';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 if ($result->num_rows > 0) { 63 $error[] = 'A book with that ISBN already exists in the database'; 64 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 // get the primary key of the record just inserted 74 $getBook_id = 'SELECT book_id FROM books 75 WHERE isbn = "'.$_POST['isbn'].'"';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 $book_id = $row['book_id']; 79 // if "Select author(s)" still selected, remove it from the array 80 if ($_POST['author'][0] == 'choose') array_shift($_POST['author']);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124 ?> 125 <form name="bookDets" id="bookDets" method="post" action=""> 126 <table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136 <th class="leftLabel">Author(s):</th> 137 <td><select name="author[]" size="6" multiple="multiple" id="author"> 138 <option value="choose"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140 if (!isset($_POST['author']) || (isset($_POST['author']) && in_array('choose',$_POST['author']))) { 141 echo 'selected="selected"'; 142 } 143 ?> 144 >Select author(s)</option> 145 <option value="other">Not listed</option>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149 if (isset($_POST['author']) && in_array($row['author_id'],$_POST['author'])) { 150 echo 'selected="selected"'; 151 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 ?> 155 </select></td> 156 </tr>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158 <th class="leftLabel">Publisher:</th> 159 <td><select name="publisher" id="publisher"> 160 <option value="0" 161 <?php if (isset($_POST['publisher']) && $_POST['publisher'] == '0') 162 echo 'selected="selected"';?>>Select publisher</option> 163 <option value="other">Not listed</option>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167 if (isset($_POST['publisher']) && $_POST['publisher'] == $row['pub_id']) 168 echo 'selected="selected"'; 169 echo '>'.$row['publisher'].'</option>'; 170 } 171 // close database connection 172 $db->close(); 173 ?> 174 </select></td> 175 </tr>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
198 </table> 199 </form> 200 </div>
Source code below from:
Beginning PHP5, Apache, and MySQL Web Development (Programmer to Programmer)
By Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, and Michael K. Glass
Published 04 February, 2005
Average rating

      Powells     Alibris

chapter 15/getprod.php (51 lines)
2 session_start(); 
3 //connect to the database - either include a connection variable file 
4 //or type the following lines: 
5 $connect = mysql_connect("localhost", "bp5am", "bp5ampass") 
6   or die("Hey loser, check your server connection.");
7 //make our database active
8 mysql_select_db("ecommerce");
9  
10 //get our variable passed through the URL 
11 $prodid = $_REQUEST['prodid']; 
12  
13 //get information on the specific product we want
14 $query = "SELECT * FROM products WHERE products_prodnum='$prodid'";
15 $results = mysql_query($query) 
Additional matches viewable in cache of chapter 15/getprod.php.
chapter 14/quickmsg.php (59 lines)
8 <body> 
9  
10 <form method="post" action="admin_transact.php">
11  
12 <p> 
13   Choose Mailing List:<br /> 
14   <select name="ml_id">
15     <option value="all">All</option> 
16 <?php 
17  
18 $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
19   or die('Could not connect to MySQL database. ' . mysql_error());
20  
21 mysql_select_db(SQL_DB, $conn);
Additional matches viewable in cache of chapter 14/quickmsg.php.
chapter 14/user.php (78 lines)
8 <body> 
9  
10 <form method="post" action="user_transact.php">
11  
12 <p> 
13   Sign up for Mailing List:<br /> 
14 </p> 
15  
16 <?php 
17  
18 $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
19   or die('Could not connect to MySQL database. ' . mysql_error());
20  
21 mysql_select_db(SQL_DB, $conn);
22  
23 if (isset($_GET['u'])) { 
Additional matches viewable in cache of chapter 14/user.php.
chapter 14/admin.php (49 lines)
8 <body> 
9  
10 <form method="post" action="admin_transact.php">
11  
12 <p> 
13   Add Mailing List:<br /> 
14   <input type="text" name="listname" maxlength="255" /> 
15   <input type="submit" name="action" value="Add New Mailing List" /> 
16 </p> 
17  
18 <p> 
19   Delete Mailing List:<br /> 
20   <select name="ml_id">
21 <?php 
22  
23 $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
24   or die('Could not connect to MySQL database. ' . mysql_error());
25  
26 mysql_select_db(SQL_DB, $conn);
Additional matches viewable in cache of chapter 14/admin.php.
chapter 15/cbashop.php (44 lines)
1 <?php 
2 //connect to the database - either include a connection variable file 
3 //or type the following lines: 
4 $connect = mysql_connect("localhost", "bp5am", "bp5ampass") 
5   or die ("Hey loser, check your server connection.");
6 mysql_select_db ("ecommerce");
7 $query = "SELECT * FROM products";
8 $results = mysql_query($query) 
9   or die(mysql_error()); 
10  
11 ?> 
12 <html> 
13 <head> 
14 <title>Comic Book Appreciation Site Product List</title> 
15 </head> 
16 <body> 
17 <div align="center"> 
18 Thanks for visiting our site! Please see our list of awesome 
19 products below, and click on the link for more information:
20 <br><br> 
21 <table width="300"> 
Source code below from:
Professional PHP5 (Programmer to Programmer)
By Edward Lecky-Thompson, Heow Eide-Goodman, Steven D. Nowicki, and Alec Cove
Published 26 November, 2004
Average rating

      Powells     Alibris

ProPHP5CodeSeparations/ch01/class.Widget.php (75 lines)
10   public function __construct($widgetID) { 
11     //The widgetID parameter is the primary key of a  
12     //record in the database containing the information
13     //for this object 
14  
15     //Create a connection handle and store it in a private member variable
16     $this->hDB = pg_connect('dbname=parts user=postgres');
17     if(! is_resource($this->hDB)) { 
18       throw new Exception('Unable to connect to the database.');
19     } 
20      
21     $sql = "SELECT \"name\", \"description\" FROM widget WHERE widgetid = $widgetID";
22     $rs = pg_query($this->hDB, $sql); 
23     if(! is_resource($rs)) { 
Additional matches viewable in cache of ProPHP5CodeSeparations/ch01/class.Widget.php.
Source code below from:
Beginning PHP 5 and MySQL: From Novice to Professional
By W. J. Gilmore
Published 21 June, 2004
Average rating

      Powells     Alibris

chapter12/listing12-10.php (36 lines)
3    Has the user submitted data? 
4    If not, display the registration form.
5    */ 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 echo file_get_contents("/templates/registration.html"); 10 11 /* Form data has been submitted. */ 12 } else { 13 14 /* Connect to the MySQL server and select database. */ 15 mysql_connect("localhost", "authenticator", "secret"); 16 mysql_select_db("chapter12");
Additional matches viewable in cache of chapter12/listing12-10.php.
chapter26/listing26-2.php (28 lines)
4    if (isset($_POST['submit'])) { 
5       // Connect to the server and select the database
6       $linkID = @mysql_connect("localhost","webuser","secret") or die("Could not connect to MySQL server");
7       @mysql_select_db("company") or die("Could not select database");
8  
9       // Retrieve the posted product information.
10       $productid = $_POST['productid']; 
11       $name = $_POST['name']; 
Additional matches viewable in cache of chapter26/listing26-2.php.
chapter28/fulltextsearch.php (31 lines)
1 <p> 
2    Search the online resources database:<br />
3    <form action="fulltextsearch.php" method="post">
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 10 <?php 11 // If the form has been submitted with supplied keywords 12 if (isset($_POST['keywords'])) { 13 include "mysql.class.php"; 14 // Connect to server and select database 15 $mysqldb = new mysql("localhost","root","","company"); 16 $mysqldb->connect();
Additional matches viewable in cache of chapter28/fulltextsearch.php.
chapter28/simplesearch.php (34 lines)
1 <p> 
2    Search the employee database:<br />
3    <form action="simplesearch.php" method="post">
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 10 <?php 11 // If the form has been submitted with a supplied last name 12 if (isset($_POST['lastname'])) { 13 14 include "mysql.class.php"; 15 // Connect to server and select database 16 $mysqldb = new mysql("localhost","jason","secret","company"); 17 $mysqldb->connect();
Additional matches viewable in cache of chapter28/simplesearch.php.
chapter16/listing16-4.php (36 lines)
5    // Has a session been initiated previously? 
6    if (! isset($_SESSION['name'])) { 
7       // If no previous session, has the user submitted the form?
8       if (isset($_POST['username'])) { 
9          $username = $_POST['username']; 
10          $pswd = $_POST['pswd']; 
11  
12          // Connect to the MySQL server and select the database
13          mysql_connect("localhost","webuser","secret");
14          mysql_select_db("chapter16");
Additional matches viewable in cache of chapter16/listing16-4.php.
Source code below from:
Web Database Applications with PHP & MySQL, 2nd Edition
By Hugh E. Williams and David Lane
Published 16 May, 2004
Average rating

      Powells     Alibris

wda/ch06/example.6-8.php (40 lines)
8 </head> 
9 <body> 
10 <form action="example.6-14.php" method="GET">
11 <?php 
12   require "db.inc"; 
13  
14   // selectDistinct() function shown in Example 6-9 goes here
15   require "example.6-9.php"; 
16  
17   // Connect to the server
18   if (!($connection = @ mysql_connect($hostName, $username, $password)))
19      showerror(); 
20  
21   if (!mysql_select_db($databaseName, $connection))
22      showerror(); 
23  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 // Produce the select list 27 // Parameters: 28 // 1: Database connection 29 // 2. Table that contains values 30 // 3. Attribute that contains values 31 // 4. <SELECT> element name 32 // 5. Optional <OPTION SELECTED> 33 selectDistinct($connection, "region", "region_name", "regionName", 34 "All"); 35 ?> 36 <br> 37 <input type="submit" value="Show Wines"> 38 </form> 39 </body> 40 </html>

wda2-winestore/search/searchform.php (56 lines)
1 <?php 
2 // Source code example for Web Database Applications with PHP and MySQL, 2nd Edition
3 // Author: Hugh E. Williams, 2001-3 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 // Unless otherwise stated, the source code distributed with this book can be 6 // redistributed in source or binary form so long as an acknowledgment appears 7 // in derived source files. 8 // The citation should list that the code comes from Hugh E. Williams and David 9 // Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & 10 // Associates.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 // This is the script that allows the to search and browse wines, and 18 // to select wines to add to their shopping cart 19
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 27 // Takes <form> heading, instructions, action, formVars name, and 28 // formErrors name as parameters 29 $template = new winestoreFormTemplate("Search", 30 "Choose regions and wine types to browse.", 31 S_SEARCH, "searchFormVars", NULL, "GET"); 32 33 $connection = DB::connect($dsn, true); 34 if (DB::isError($connection)) 35 trigger_error($connection->getMessage(), E_USER_ERROR); 36
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 // Load the regions from the region table 40 $regionResult = $connection->query("SELECT * FROM region"); 41 if (DB::isError($regionResult))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44 // Load the wine types from the wine_type table 45 $wineTypeResult = $connection->query("SELECT * FROM wine_type"); 46 if (DB::isError($wineTypeResult))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 49 $template->selectWidget("region_name", "Region name:", 50 "region_name", $regionResult); 51 52 $template->selectWidget("wine_type", "Wine type:", 53 "wine_type", $wineTypeResult);

wda/appf/mysql_sessions.inc (189 lines)
19  
20 // The database connection
21 $connection = NULL;
22    
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 29 function sessionOpen($database_name, $table_name) 30 { 31 // Save the database connection in a global variable 32 global $connection; 33
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 37 // Database credentials 38 global $hostName;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 42 if (!($connection = @ mysql_connect($hostName, $username, $password))) 43 showerror(); 44 45 if (!mysql_select_db($database_name, $connection)) 46 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 { 61 // Access the DBMS connection 62 global $connection; 63
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 67 // Formulate a query to find the session identified by $sess_id 68 $search_query = "SELECT * FROM {$session_table} 69 WHERE session_id = '{$sess_id}'";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71 // Execute the query 72 if (!($result = @ mysql_query($search_query, $connection))) 73 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 { 88 // Access the DBMS connection 89 global $connection; 90
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 96 $search_query = "SELECT session_id FROM {$session_table} 97 WHERE session_id = '{$sess_id}'";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99 // Execute the query 100 if (!($result = @ mysql_query($search_query, $connection))) 101 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109 110 if (!mysql_query($insert_query, $connection)) 111 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 121 if (!mysql_query($update_query, $connection)) 122 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
139 { 140 // Access the DBMS connection 141 global $connection; 142
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 149 if (!($result = @ mysql_query($delete_query, $connection))) 150 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155 // This function is called on a session's start up with the 156 // probability specified in session.gc_probability. Performs 157 // garbage collection by removing all sessions that haven't been
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
163 { 164 // Access the DBMS connection 165 global $connection; 166
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
174 175 if (!($result = @ mysql_query($delete_query, $connection))) 176 showerror();

wda/ch06/example.6-4.php (68 lines)
10 <?php 
11    // Open a connection to the server and USE the winestore
12    $connection = mysql_connect("localhost","fred","shhh");
13    mysql_select_db("winestore", $connection);
14  
15    // Run a query on the wine table in the winestore database to retrieve
16    // one row 
17    $result = mysql_query ("SELECT * FROM wine LIMIT 1", $connection);
18  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 50 // Print out selected index information 51 if ($info->primary_key == 1)

wda/ch08/example.8-12.php (57 lines)
4  
5 function formerror(&$template, $message, &$errors)
6 { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 13 if (!($connection = @ mysql_connect("localhost", "fred", "shhh"))) 14 die("Could not connect to database"); 15 16 $phonebook_id = mysqlclean($_POST, "phonebook_id", 5, $connection); 17 $firstname = mysqlclean($_POST, "firstname", 50, $connection); 18 $surname = mysqlclean($_POST, "surname", 50, $connection); 19 $phone = mysqlclean($_POST, "phone", 20, $connection); 20
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 if (empty($firstname)) 27 formerror($template, "The first name field cannot be blank.", $errors); 28 29 if (empty($surname)) 30 formerror($template, "The surname field cannot be blank.", $errors); 31 32 if (empty($phone)) 33 formerror($template, "The phone field cannot be blank", $errors); 34
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 // If we made it here, then the data is valid 43 if (!mysql_select_db("telephone", $connection)) 44 showerror();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 52 if (!(@ mysql_query ($query, $connection))) 53 showerror();
Source code below from:
PHP 5 Fast & Easy Web Development (Fast & Easy Web Development)
By Julie C. Meloni
Published 11 May, 2004
Average rating

      Powells     Alibris

do_addrecord.php (74 lines)
3 //check for required fields 
4 if ((!$_POST[id]) || (!$_POST[format]) || (!$_POST[title])) {
5     header("Location: /show_addrecord.html"); 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11 $table_name ="my_music"; 12 13 //connect to MySQL and select database to use 14 $connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error()); 15 16 $db = @mysql_select_db($db_name,$connection) or die(mysql_error()); 17 18 //create SQL statement and issue query 19 $sql = "INSERT INTO $table_name (id, format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq) VALUES ('$_POST[id]', '$_POST[format]', '$_POST[title]', '$_POST[artist_fn]', '$_POST[artist_ln]', '$_POST[rec_label]', '$_POST[my_notes]', '$_POST[date_acq]')"; 20 21 $result = @mysql_query($sql,$connection)or die(mysql_error());
Additional matches viewable in cache of do_addrecord.php.
contact_menu_ch22.php (128 lines)
4  
5 //check if user is coming from a form
6 if ($_POST[op] == "ds") { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 46 <P><input type=\"submit\" name=\"submit\" value=\"login\"></P> 47 </FORM>"; 48 49 } else if ($show_menu == "yes") { 50 51 //set up table and database names 52 $db_name ="testDB"; 53 $table_name ="my_contacts"; 54 55 //connect to server and select database 56 $connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error()); 57 $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
Additional matches viewable in cache of contact_menu_ch22.php.
manage.php (93 lines)
2  
3 //set up table and database names
4 $db_name ="testDB"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 21 <p><input type=submit name=\"submit\" value=\"Submit Form\"></p> 22 </form>"; 23 24 } else if (($_POST[op] == "ds") && ($_POST[action] == "sub")) { 25 26 //trying to subscribe;validate email address 27 if ($_POST[email_addr] == ""){ 28 header("Location:http://127.0.0.1/manage.php"); 29 exit; 30 } 31 32 //connect to server and select database 33 $connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error()); 34 $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
Additional matches viewable in cache of manage.php.
do_modcontact.php (98 lines)
2 session_start(); 
3 //check for required form variables
4 if ((!$_POST[f_name]) || (!$_POST[l_name])) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 exit; 7 } else { 8 //if form variables are present,start a session 9 session_start(); 10 } 11 //check for validity of user 12 if ($_SESSION[valid] != "yes"){ 13 header("Location:http://127.0.0.1/contact_menu.php"); 14 exit; 15 } 16 17 //set up table and database names 18 $db_name ="testDB"; 19 $table_name ="my_contacts"; 20 21 //connect to server and select database 22 $connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error()); 23 $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
Additional matches viewable in cache of do_modcontact.php.
do_addcontact.php (91 lines)
2  
3 //check for required form variables
4 if ((!$_POST[f_name]) || (!$_POST[l_name])) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 exit; 7 }else { 8 //if form variables are present,start a session 9 session_start(); 10 } 11 12 //check for validity of user 13 if ($_SESSION[valid] != "yes") { 14 header("Location:http://127.0.0.1/contact_menu.php"); 15 exit; 16 } 17 18 //set up table and database names 19 $db_name ="testDB"; 20 $table_name ="my_contacts"; 21 22 //connect to server and select database 23 $connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error()); 24 $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
Additional matches viewable in cache of do_addcontact.php.
Source code below from:
Essential PHP Tools: Modules, Extensions, and Accelerators
By David Sklar
Published 15 March, 2004
Average rating

      Powells     Alibris

1590592808-1/Chapter04/ex97.php (27 lines)
1 require 'DB.php'; 
2 // connect to the database
3 $dbh = DB::connect('mysql://phpgems:phpgems1@localhost/phpgems');
4 // we want our results back as associative arrays 
5 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 
6 // was a search term specified? 
7 if ($_REQUEST['search_term']) { 
8     // make the search term accessible from the template -- we escape it 
9     // to avoid any XSS attacks 
10     $smarty->assign('search_term', htmlentities($_REQUEST['search_term'])); 
11     // retrieve all rows from the ice_cream table where flavor contains 
12     // the search term 
13     $ice_cream = $dbh->getAll('SELECT * FROM ice_cream WHERE flavor LIKE ?',
14                               array('%'.$_REQUEST['search_term'].'%')); 
15 } else { 
16     // no search term, so retrieve all rows 
17     $ice_cream = $dbh->getAll('SELECT * FROM ice_cream');
18 } 
19 // make the ice cream data accessible from the template 
20 $smarty->assign('flavors',$ice_cream); 
21 // display the template: XML or HTML 
22 if ($_REQUEST['format'] == 'xml') {
23     header('Content-Type: text/xml'); 
24     $smarty->display('show-icecream-xml.tpl'); 

Chapter04/ex97.php (27 lines)
1 require 'DB.php'; 
2 // connect to the database
3 $dbh = DB::connect('mysql://phpgems:phpgems1@localhost/phpgems');
4 // we want our results back as associative arrays 
5 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 
6 // was a search term specified? 
7 if ($_REQUEST['search_term']) { 
8     // make the search term accessible from the template -- we escape it 
9     // to avoid any XSS attacks 
10     $smarty->assign('search_term', htmlentities($_REQUEST['search_term'])); 
11     // retrieve all rows from the ice_cream table where flavor contains 
12     // the search term 
13     $ice_cream = $dbh->getAll('SELECT * FROM ice_cream WHERE flavor LIKE ?',
14                               array('%'.$_REQUEST['search_term'].'%')); 
15 } else { 
16     // no search term, so retrieve all rows 
17     $ice_cream = $dbh->getAll('SELECT * FROM ice_cream');
18 } 
19 // make the ice cream data accessible from the template 
20 $smarty->assign('flavors',$ice_cream); 
21 // display the template: XML or HTML 
22 if ($_REQUEST['format'] == 'xml') {
23     header('Content-Type: text/xml'); 
24     $smarty->display('show-icecream-xml.tpl'); 
Source code below from:
Learning PHP 5
By David Sklar
Published July, 2004
Average rating

      Powells     Alibris

LearningPHP5Code/Chapter10/example-10-13.php (15 lines)
1 require 'DB.php'; 
2 // Connect to the database
3 $db = DB::connect('mysql://hunter:w)mp3s@db.example.com/restaurant');
4 // Open the CSV file for writing 
5 $fh = fopen('dishes.csv','wb'); 
6  
7 $dishes = $db->query('SELECT dish_name, price, is_spicy FROM dishes');
8 while ($row = $dishes->fetchRow()) { 
9     // Turn the array from fetchRow() into a CSV-formatted string
10     $line = make_csv_line($row); 
11     // Write the string to the file. No need to add a newline on 

LearningPHP5Code/Chapter1/example-1-07.php (31 lines)
2 require 'DB.php'; 
3 // Connect to MySQL running on localhost with username "menu"
4 // and password "good2eaT", and database "dinner"
5 $db = DB::connect('mysql://menu:good2eaT@localhost/dinner');
6 // Define what the allowable meals are 
7 $meals = array('breakfast','lunch','dinner'); 
8 // Check if submitted form parameter "meal" is one of
9 // "breakfast", "lunch", or "dinner" 
10 if (in_array($meals, $_POST['meal'])) { 
11     // If so, get all of the dishes for the specified meal 
12     $q = $dbh->query("SELECT dish,price FROM meals WHERE meal LIKE '" . 
13                      $_POST['meal'] ."'"); 
14     // If no dishes were found in the database, say so

LearningPHP5Code/AppendixC/answer-7-3.php (84 lines)
1 <?php 
2 require 'DB.php'; 
3 require 'formhelpers.php'; // load the form element printing functions
4  
5 $db = DB::connect('mysql://hunter:w)mp3s@db.example.com/restaurant');
6 if (DB::isError($db)) { die("Can't connect: " . $db->getMessage()); }
7  
8 $db->setErrorHandling(PEAR_ERROR_DIE); 
9 $db->setFetchMode(DB_FETCHMODE_ASSOC); 
10  
11 // get the array of dish names from the database
12 $dish_names = array(); 
13 $res = $db->query('SELECT dish_name FROM dishes');
14 while ($row = $res->fetchRow()) { 
15     $dish_names[] = $row['dish_name']; 
Additional matches viewable in cache of LearningPHP5Code/AppendixC/answer-7-3.php.
LearningPHP5Code/AppendixC/answer-12-4.php (63 lines)
3  
4 Line 6: Two colons are needed between DB and connect.
5  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 <?php 26 require 'DB.php'; 27 require 'formhelpers.php'; 28 29 // Connect to the database 30 $db = DB::connect('mysql://hunter:w)mp3s@db.example.com/restaurant'); 31 if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); } 32 33 // Set up automatic error handling 34 $db->setErrorHandling(PEAR_ERROR_DIE); 35 36 // Set up fetch mode: rows as associative arrays 37 $db->setFetchMode(DB_FETCHMODE_ASSOC); 38 39 // get the array of dish names from the database 40 $dish_names = array(); 41 $res = $db->query('SELECT dish_id,dish_name FROM dishes'); 42 while ($row = $res->fetchRow()) { 43 $dish_names[ $row['dish_id'] ] = $row['dish_name'];
Additional matches viewable in cache of LearningPHP5Code/AppendixC/answer-12-4.php.
LearningPHP5Code/AppendixC/answer-7-4.php (133 lines)
9  
10 The form that inserts a new customer:
11 <?php 
12 require 'DB.php'; 
13 require 'formhelpers.php';
14  
15 // Connect to the database
16 $db = DB::connect('mysql://hunter:w)mp3s@db.example.com/restaurant');
17 if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); }
18  
19 // Set up automatic error handling 
20 $db->setErrorHandling(PEAR_ERROR_DIE); 
21  
22 // Set up fetch mode: rows as associative arrays 
23 $db->setFetchMode(DB_FETCHMODE_ASSOC); 
24  
25 // get the array of dish names from the database
26 $dish_names = array(); 
27 $res = $db->query('SELECT dish_id,dish_name FROM dishes');
28 while ($row = $res->fetchRow()) { 
29     $dish_names[ $row['dish_id'] ] = $row['dish_name']; 
Additional matches viewable in cache of LearningPHP5Code/AppendixC/answer-7-4.php.
Source code below from:
Core PHP Programming, Third Edition
By Leon Atkinson and Zeev Suraski
Published 08 August, 2003
Average rating

      Powells     Alibris

corephp/17-47.php (68 lines)
1 <?php 
2     //connect to database
3     $Link = pg_connect(" " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 "password=freetrade"); 7 8 //print information about connection 9 print("Connection established<br>\n"); 10 print("Host: " . pg_host($Link) . "<br>\n"); 11 print("Port: " . pg_port($Link) . "<br>\n"); 12 print("Database: " . pg_dbname($Link) . "<br>\n"); 13 print("Options: " . pg_options($Link) . "<br>\n"); 14 print("<br>\n"); 15 16 //create query 17 $Query = "SELECT * " . 18 "FROM session "; 19
Additional matches viewable in cache of corephp/17-47.php.
corephp/17-28.php (18 lines)
1 <?php 
2     //connect to database
3     $Link = odbc_connect("mysql-galt", "leon", "");
4  
5     //switch to freetrade database
6     odbc_do($Link, "USE ft3"); 
7  
8     // execute query 
9     $Query = "SELECT Name, SalePrice " .
10     $Query .= "FROM sku "; 
11     $Result = odbc_do($Link, $Query); 
12     while(odbc_fetch_into($Result, $field)) 
13     { 
14         print($field[0] . ": $" . 
15         number_format($field[1], 2) . "<br>");
16     } 
17     odbc_close($Link); 

corephp/17-36.php (77 lines)
1 <?php 
2     //connect to database
3     $Link = ocilogon("scott", "tiger"); 
4  
5     //check that we made the connection
6     if($Error = ocierror()) 
7     { 
8         die('<p style="color: red">Connection Failed--' .
9         $Error["message"] . "</p>"); 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 //assemble query 13 $Query = "SELECT * FROM emp "; 14
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 32 //build headers from column information 33 print("<tr>\n");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 75 //close connection 76 ocilogoff($Link);

corephp/23-6.php (161 lines)
21  
22     //connect to database
23     if(!($dbLink = mysql_connect("localhost", "httpd", "")))
24     { 
25         print("Couldn't connect to database!<br>\n");
26     } 
27  
28     //select database, then test for failure
29     if(!($dbResult = mysql_query("USE test", $dbLink))) 
30     { 
31         print("Couldn't use test database!<br>\n");
32     } 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 //we have a session, so check it 49 $Query = "SELECT SessionData, Invoice " . 50 "FROM session " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 81 //insert session to database 82 $Query = "INSERT INTO session " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123 124 //show form for getting name 125 print("<form " . 126 "action=\"{$_SERVER['PHP_SELF']}\" " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133 "<br>\n" . 134 "</form>"); 135

corephp/23-8.php (182 lines)
8  
9     //connect to server, then test for failure
10     if(!($dbLink = mysql_connect("localhost", "httpd", "")))
11     { 
12         print("Failed to connect to database!<br>\n");
13         print("Aborting!<br\n"); 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16 17 //select database, then test for failure 18 if(!($dbResult = mysql_query("USE test", $dbLink))) 19 { 20 print("Can't use the test database!<BR>\n"); 21 print("Aborting!<BR>\n");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 print("<ul>\n"); 34 $Query = "SELECT ID, Title, Created " . 35 "FROM bbsMessage " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61 /* 62 ** print out a form for adding a message with 63 ** parent id given 64 */ 65 function postForm($parentID, $useTitle) 66 { 67 print("<form action=\"{$_SERVER['PHP_SELF']}\" " . 68 "method=\"post\">\n" .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 "</table>\n" . 101 "</form>\n"); 102 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104 /* 105 ** perform actions 106 */
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132 { 133 $Query = "SELECT ID, Title, Poster, Created, " . 134 "Parent, Body " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
166 "</table>\n"); 167 postForm($row['ID'], "RE: {$row['Title']}"); 168 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177 showMessages(0); 178 postForm(0, ""); 179 }
Source code below from:
PHP MySQL Website Programming: Problem - Design - Solution
By Chris Lea, Mike Buzzard, Dilip Thomas, and Jessey-White Cinis
Published March, 2003
Average rating

      Powells     Alibris

DVD Life/_lib/_classes/class.products.php (630 lines)
22     /**  
23      * Property containing the PEAR database object reference
24      *  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 * 44 * Instanciates the PEAR DB module to handle all database connectivity 45 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 50 // Instanciate the database connection 51 $this->_oConn =& DB::connect(DSN); 52
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 // Build SQL query 78 $sql = "SELECT 79 product_quantity
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131 132 // SELECT METHODS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 133
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146 // Build SQL query 147 $sql = "SELECT 148 product_sku,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
151 product_rating, 152 product_format, 153 product_release_dt,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 $return["Rating"] = $aTmpRow["product_rating"]; 187 $return["Format"] = $aTmpRow["product_format"]; 188 $return["Image"] = $aTmpRow["product_img_path"];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233 // Build the SQL query 234 $sql = "SELECT 235 product_id,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
239 product_rating, 240 product_format, 241 product_release_dt,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
279 $return[$i]["Rating"] = $aTmpRow["product_rating"]; 280 $return[$i]["Format"] = $aTmpRow["product_format"]; 281 $return[$i]["Image"] = $aTmpRow["product_img_path"];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311 /** 312 * Counts the number of products in the database 313 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
327 // Build SQL query 328 $sql = "SELECT 329 COUNT(product_id)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
342 343 // Return the number of (active?) products in the database 344 return $return;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
349 /** 350 * Adds a product to the database 351 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
360 // Build SQL query 361 // Convert the release date to a SQL date format 362 $sql = "INSERT INTO ".PREFIX."_products (
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
366 product_rating, 367 product_format, 368 product_release_dt,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
377 '".$aArgs["Rating"]."', 378 '".$aArgs["Format"]."', 379 '".date("Y-m-d",$aArgs["Release Date"])."',
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
395 // Use MySQL's LAST_INSERT_ID() method to query for the insert id 396 $sql = "SELECT LAST_INSERT_ID()"; 397
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
408 // Check that the file is uploaded and that the product has been 409 // inserted into the database successfully 410 if (strcmp("",$aArgs["Image"]["name"]) &&
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
416 417 // Build update query to include the image path in the database 418 $sql = "UPDATE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
444 /** 445 * Updates a product in the database 446 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
455 // Build the SQL query 456 // Convert the release date to an SQL date format 457 $sql = "UPDATE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
463 product_rating = '".$aArgs["Rating"]."', 464 product_format = '".$aArgs["Format"]."', 465 product_release_dt = '".date("Y-m-d",$aArgs["Release Date"])."',
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
489 490 // Build update query to include the image path in the database 491 $sql = "UPDATE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
590 /** 591 * Soft-Deletes a product from the database 592 *
Source code below from:
PHP Graphics Handbook
By Jason E. Sweat, Allan Kent, and Mitja Slenc
Published 25 February, 2003
Average rating

      Powells     Alibris

ch-5,6,7/Ch07/adodb/drivers/adodb-informix72.inc.php (303 lines)
10  
11   Informix port by Mitchell T. Young (mitch@youngfamily.org)
12  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 */ 16 17 class ADODB_informix72 extends ADOConnection { 18 var $databaseType = "informix72"; 19 var $dataProvider = "informix"; 20 var $replaceQuote = "''"; // string to use to replace quotes 21 var $fmtDate = "'Y-m-d'"; 22 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 23 var $hasInsertID = true; 24 var $hasAffectedRows = true; 25 var $metaTablesSQL="select tabname from systables"; 26 var $metaColumnsSQL = "select colname, coltype, collength from syscolumns c, systables t where c.tabid=t.tabid and tabname='%s'"; 27 var $concat_operator = '||';
Additional matches viewable in cache of ch-5,6,7/Ch07/adodb/drivers/adodb-informix72.inc.php.
ch-5,6,7/Ch07/adodb/drivers/adodb-postgres64.inc.php (687 lines)
8    
9   Original version derived from Alberto Cerezal (acerezalp@dbnet.es) - DBNet Informatica & Comunicaciones. 
10   08 Nov 2000 jlim - Minor corrections, removing mysql stuff 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19 */ 20 21 class ADODB_postgres64 extends ADOConnection{ 22 var $databaseType = 'postgres64'; 23 var $dataProvider = 'postgres'; 24 var $hasInsertID = true; 25 var $_resultid = false; 26 var $concat_operator='||'; 27 var $metaTablesSQL = "select tablename from pg_tables where tablename not like 'pg\_%' order by 1"; 28 //"select tablename from pg_tables where tablename not like 'pg_%' order by 1"; 29 var $isoDates = true; // accepts dates in ISO format 30 var $sysDate = "CURRENT_DATE"; 31 var $sysTimeStamp = "CURRENT_TIMESTAMP";
Additional matches viewable in cache of ch-5,6,7/Ch07/adodb/drivers/adodb-postgres64.inc.php.
ch-5,6,7/Ch07/adodb/drivers/adodb-mssql.inc.php (701 lines)
17 //---------------------------------------------------------------- 
18 // MSSQL returns dates with the format Oct 13 2002 or 13 Oct 2002
19 // and this causes tons of problems because localized versions of  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 //--------------------------------------------------------------------------- 52 // Call this to autoset $ADODB_mssql_date_order at the beginning of your code, 53 // just after you connect to the database. Supports mdy and dmy only. 54 // Not required for PHP 4.2.0 and above. 55 function AutoDetect_MSSQL_Date_Order($conn) 56 { 57 global $ADODB_mssql_date_order; 58 $adate = $conn->GetOne('select getdate()'); 59 if ($adate) { 60 $anum = (int) $adate; 61 if ($anum > 0) { 62 if ($anum > 31) { 63 //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); 64 } else 65 $ADODB_mssql_date_order = 'dmy';
Additional matches viewable in cache of ch-5,6,7/Ch07/adodb/drivers/adodb-mssql.inc.php.
ch-5,6,7/Ch07/adodb/drivers/adodb-oci8.inc.php (1016 lines)
17 /* 
18 NLS_Date_Format
19 Allows you to use a date format other than the Oracle Lite default. When a literal
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 NLS_DATE_FORMAT='RR-MM-DD' 34 35 You can also modify the date format using the ALTER SESSION command. 36 */ 37 class ADODB_oci8 extends ADOConnection { 38 var $databaseType = 'oci8'; 39 var $dataProvider = 'oci8'; 40 var $replaceQuote = "''"; // string to use to replace quotes 41 var $concat_operator='||'; 42 var $sysDate = "TRUNC(SYSDATE)"; 43 var $sysTimeStamp = 'SYSDATE'; 44 45 var $_stmt; 46 var $_commit = OCI_COMMIT_ON_SUCCESS; 47 var $_initdate = true; // init date to YYYY-MM-DD 48 var $metaTablesSQL = "select table_name from cat where table_type in ('TABLE','VIEW')"; 49 var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno"; 50 var $_bindInputArray = true;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 var $session_sharing_force_blob = false; // alter session on updateblob if set to true 64 var $firstrows = true; // enable first rows optimization on SelectLimit() 65 var $selectOffsetAlg1 = 100; // when to use 1st algorithm of selectlimit. 66 var $NLS_DATE_FORMAT = 'YYYY-MM-DD'; 67 var $useDBDateFormatForTextInput=false; 68 69 // var $ansiOuter = true; // if oracle9 70 71 function ADODB_oci8() 72 { 73 global $ADODB_PHPVER; 74 75 $this->_hasOCIFetchStatement = $ADODB_PHPVER >= 0x4200; 76 } 77 78 79 /* 80 81 4 modes of connection are supported: 82 83 a. $conn->Connect(false,'scott','tiger'); // local database 84 85 b. $conn->Connect(false,'scott','tiger',$tnsname); // from tnsnames.ora
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137 if ($this->_connectionID === false) return false; 138 if ($this->_initdate) { 139 $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'"); 140 } 141 142 // looks like: 143 // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production 144 // $vers = OCIServerVersion($this->_connectionID); 145 // if (strpos($vers,'8i') !== false) $this->ansiOuter = true; 146 return true; 147 } 148 149 function ServerInfo() 150 { 151 $arr['compat'] = $this->GetOne('select value from sys.database_compatible_level'); 152 $arr['description'] = @OCIServerVersion($this->_connectionID); 153 $arr['version'] = ADOConnection::_findvers($arr['description']);
Additional matches viewable in cache of ch-5,6,7/Ch07/adodb/drivers/adodb-oci8.inc.php.
ch-5,6,7/Ch07/adodb/adodb-connection.inc.php (1630 lines)
14     /** 
15      * Connection object. For connecting to databases, and executing queries.
16      */  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 var $database = ''; /// Name of database to be used. 24 var $host = ''; /// The hostname of the database server 25 var $user = ''; /// The username which is used to connect to the database server. 26 var $password = ''; /// Password for the username. For security, we no longer store it. 27 var $debug = false; /// if set to true will output sql statements 28 var $maxblobsize = 64000; /// maximum size of blobs or large text fields -- some databases die otherwise like foxpro 29 var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase 30 var $fmtDate = "'Y-m-d'"; /// used by DBDate() as the default date format used by the database 31 var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; /// used by DBTimeStamp as the default timestamp fmt. 32 var $true = '1'; /// string that represents TRUE for a database 33 var $false = '0'; /// string that represents FALSE for a database 34 var $replaceQuote = "\\'"; /// string to use to replace quotes 35 var $charSet=false; /// character set to use - only for interbase 36 var $metaTablesSQL = ''; 37 //-- 38 var $hasInsertID = false; /// supports autoincrement ID? 39 var $hasAffectedRows = false; /// supports affected rows for update/delete? 40 var $hasTop = false; /// support mssql/access SELECT TOP 10 * FROM TABLE 41 var $hasLimit = false; /// support pgsql/mysql SELECT * FROM TABLE LIMIT 10 42 var $readOnly = false; /// this is a readonly database - used by phpLens
Additional matches viewable in cache of ch-5,6,7/Ch07/adodb/adodb-connection.inc.php.
Source code below from:
Dreamweaver MX: Advanced PHP Web Development
By Glasshaus Author Team
Published January, 2003
Average rating

      Powells     Alibris

cms/class/Database.php (67 lines)
2  #################################################### 
3  # CMS Database Class                               #
4  #################################################### 
5   
6 class Database {
7  
8     // Database Connection Variables you will need to change these   
9     var $dbName = "glasshausCMS"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13 14 function Database(){ 15
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 18 function DB_databaseConnect(){ 19 // Connect to the mySQL Server and Select the database 20 $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass); 21 if (!$dbLink) 22 die ("Database Class: Couldn't connect to mySQL Server"); 23 mysql_select_db($this->dbName, $dbLink) 24 or die ("Database Class: Couldn't open Database"); 25 return $dbLink;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 $dbResult = mysql_query($query, $dbLink) 31 or die ("Database Class: MySQL Error: " . mysql_error() ); 32 return $dbResult;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 47 function DB_closeDatabase($dbLink){ 48 // Close MySQL Connection 49 mysql_close ($dbLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 function DB_date2mysql($date){ 53 // Change a date from US Format (dd/mm/yyyy) to mySQL format 54 $temp = explode("/",$date);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 function DB_mysql2date($date){ 61 // Change a date from mySQL (yyyy-mm-dd) to US Format 62 $temp = explode("-",$date);

cms/class/adminArticles.php (301 lines)
1 <?php 
2 require_once("../class/database.php");
3 #################################################### 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 # Inherits 7 # DB_date2mysql($date) : DB_mysql2date($date) : DB_databaseConnect() 8 # DB_executeQuery($query,$Link) : DB_getRecordID() : DB_getRecords($Result) 9 # DB_closeDatabase($Link) 10 class adminArticles extends Database{ 11
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 $this->date = date("m/d/Y"); 33 $this->articleLink = $this->DB_databaseConnect(); 34 $this->getVars(); 35 $this->performAction(); 36 $this->showRecord();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44 $this->createadminMenu(); 45 $this->DB_closeDatabase($this->articleLink); 46 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 if($this->id > 0 ){ 69 $query = sprintf("SELECT id,title,author,date,body,menuID 70 FROM tblarticles WHERE id = %s",$this->id);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 function readPrimaryMenu(){ 82 $query = "SELECT id,label,position,link"; 83 $query .=" FROM tblmainmenu ORDER BY position ASC";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 // Create Main Content Menu Link Menu 97 $menuLink .= "<select name='menuID' id='menuID'>"; 98 foreach($this->menuPrimary as $menuItem){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 $menuLink .= "<option value=\"{$menuItem['id']}\""; 101 $menuLink .= " selected>{$menuItem['label']}</option>"; 102 } else {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106 } 107 $menuLink .= "</select>"; 108 $this->menuLink = $menuLink;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 $menuList = "<div id=\"articleMenu\" align=\"center\">"; 114 $menuList .= "<span class=\"formHeader\">Select Menu:</span>"; 115 $menuList .= "<form name=\"menuForm\" method=\"post\" action=\""; 116 $menuList .= $PHP_SELF . "\" >"; 117 $menuList .= "<select name=\"sideMenuID\" id=\"menuOption\""; 118 $menuList .= " onChange=\"menuForm.submit()\">"; 119 foreach($this->menuPrimary as $menuItem){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121 $menuList .= "<option value=\"{$menuItem['id']}\""; 122 $menuList .= " selected>{$menuItem['label']}</option>"; 123 } else {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 } 128 $menuList .= "</select>"; 129 $menuList .= "</form>"; 130 $menuList .= "</div>";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135 // Create Article Listings for Navigation 136 $query = sprintf("SELECT id,title,author,date,body,menuID 137 FROM tblarticles WHERE menuID = '%s'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161 162 function performAction(){ 163 if($_POST['Add'] == "Add"){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
265 $imageHTML .= "<div align='center'>"; 266 $imageHTML .= "<form name='dataForm$count' method='post' action='" . $_SERVER['PHP_SELF'] . "'>"; 267 $imageHTML .= "<img ";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
270 $imageHTML .= "<br>"; 271 $imageHTML .= "<span class='formHeader'>{$image['name']}</span>"; 272 $imageHTML .= "<br><br>";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275 $imageHTML .= "<input name='Remove' type='submit' value='Remove'>"; 276 $imageHTML .= "</form></div>"; 277 $count++;

cms/class/adminMenu.php (185 lines)
1 <?php 
2 require_once("database.php");
3 #################################################### 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 # Inherits 7 # DB_date2mysql($date) : DB_mysql2date($date) : DB_databaseConnect() 8 # DB_executeQuery($query,$Link) : DB_getRecordID() 9 # DB_getRecords($Result) : DB_closeDatabase($Link) 10 11 class adminMenu extends Database{ 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 function adminMenu(){ 25 $this->menuLink = $this->DB_databaseConnect(); 26 $this->performActions(); 27 $this->createadminMenu();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 $this->createAdminButtons(); 31 $this->DB_closeDatabase($this->menuLink); 32 } 33 34 function performActions(){ 35 if($_POST['Up']=='Up'){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 function createMenuArray(){ 56 $query = "SELECT id,label,position,link FROM tblmainmenu ORDER BY position ASC"; 57 $result = $this->DB_executeQuery($query,$this->menuLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 function changePosition($direction){ 69 $selected = $_POST['menu']; 70 $this->createMenuArray();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 function editMenuItem(){ 90 $selected = $_POST['menu']; 91 $query = sprintf("SELECT id,label,position,link FROM tblmainmenu 92 WHERE id='%s'", $selected); 93 $result = $this->DB_executeQuery($query,$this->menuLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99 function updateMenuItem(){ 100 $selected = $_POST['menu']; 101 $label = $_POST['label'];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103 $query = sprintf("UPDATE tblmainmenu SET label='%s', link='%s' 104 WHERE id = '%s'",$label,$link,$selected); 105 $result = $this->DB_executeQuery($query,$this->menuLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 function addMenuItem(){ 109 $query = "SELECT id,label,position,link FROM tblmainmenu ORDER BY position DESC"; 110 $result = $this->DB_executeQuery($query,$this->menuLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126 $userMenu = "<div align=\"center\">"; 127 $userMenu .= "<select name=\"menu\" size=\"10\" id=\"menu\">"; 128 $query = "SELECT id,label,position,link FROM tblmainmenu ORDER BY position ASC"; 129 $result = $this->DB_executeQuery($query,$this->menuLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131 if($_POST['menu'] == $row['id']){ 132 $userMenu .= "<option value=\"{$row['id']}\" selected>".$row['label']; 133 $userMenu .= "</option>";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137 } 138 $userMenu .= "</select>"; 139 $userMenu .= "</div>";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144 $buttons="<br><div align=\"center\">"; 145 $buttons .= "<span class=\"formButton\"><input name=\"Up\" type=\"submit\""; 146 $buttons .= " value=\"Up\"></span>"; 147 $buttons .= "<span class=\"formButton\"><input name=\"Down\" type=\"submit\""; 148 $buttons .= " value=\"Down\"></span>"; 149 $buttons .= "<span class=\"formButton\"><input name=\"Edit\" type=\"submit\""; 150 $buttons .= " value=\"Edit\"></span>"; 151 $buttons .= "<span class=\"formButton\"><input name=\"Delete\" type=\"submit\""; 152 $buttons .= " value=\"Delete\"></span>";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
159 if($this->label == ""){ 160 $buttons .= "<span class=\"formButton\"><input name=\"Add\""; 161 $buttons .= " type=\"submit\" value=\"Add\"></span>"; 162 } else { 163 $buttons .= "<span class=\"formButton\"><input name=\"New\""; 164 $buttons .= " type=\"submit\" value=\"New\"></span>"; 165 $buttons .= "<span class=\"formButton\"><input name=\"Update\""; 166 $buttons .= " type=\"submit\" value=\"Update\"></span>";

cms/class/adminNews.php (205 lines)
1 <?php 
2 require_once("../class/database.php");
3 #################################################### 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 # Inherits 7 # DB_date2mysql($date) : DB_mysql2date($date) : DB_databaseConnect() 8 # DB_executeQuery($query,$Link) : DB_getRecordID() : DB_getRecords($Result) 9 # DB_closeDatabase($Link) 10 11 class adminNews extends Database{ 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 $this->date = date("m/d/Y"); 31 $this->newsLink = $this->DB_databaseConnect(); 32 $this->getVars(); 33 $this->showRecord(); 34 $this->performActions(); 35 $this->createNewsList();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 $this->createadminMenu(); 39 $this->DB_closeDatabase($this->newsLink); 40 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59 60 function performActions(){ 61 if($_POST['Add'] == "Add"){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 function createNewsList(){ 128 $query = "SELECT id,title,author,date,body FROM tblnews ORDER BY id DESC"; 129 $this->newsResult = $this->DB_executeQuery($query,$this->newsLink);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169 if($this->id > 0 ){ 170 $query = sprintf("SELECT id,title,author,date,body 171 FROM tblnews WHERE id = %s",$this->id);

training/mysql.php (369 lines)
1 <?php 
2 class MySqlConnection
3 { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 if ($this->connectionId = mysql_connect($this->hostname, $this->username, $this->password)) 50 { 51 $this->isOpen = ($this->database == "") ? true : mysql_select_db($this->database, $this->connectionId); 52 } 53 else 54 { 55 // this error information gets added in test open 56 57 // $error_message = mysql_error() ;
Additional matches viewable in cache of training/mysql.php.
Source code below from:
PHP Bible, 2nd Edition
By Tim Converse and Joyce Park
Published 11 September, 2002
Average rating

      Powells     Alibris

PHPBible_2ndEd/ch17/form_check.php (31 lines)
6  
7 // Check database user
8 // Webvars.inc is a file with $host, $db_user, and $password values in it 
9 include("/home/phpuser/Webvars.inc"); 
10 mysql_connect($hostname, $db_user, $password) or die("You are not the database user I'm looking for");
11 mysql_select_db("captainslog");
12  
13 // Check form user
14 $post_try_user = $_POST['try_user']; 
15 $post_try_date = $_POST['try_date']; 
Additional matches viewable in cache of PHPBible_2ndEd/ch17/form_check.php.
PHPBible_2ndEd/ch21/date_prefs.php (139 lines)
5  
6 // Open connection to the database
7 mysql_connect("localhost", "mysqluser", "sesame") or die("Failure to communicate with database");
8 mysql_select_db("test");
9  
10 // If the form has been submitted, record the preferences
11 if ($_POST['submit'] == 'Submit') { 
12   $height = $_POST['height']; 
Additional matches viewable in cache of PHPBible_2ndEd/ch21/date_prefs.php.
PHPBible_2ndEd/ch21/mult_chkbx.php (122 lines)
5 /* 
6 // Open connection to the database
7 mysql_connect("localhost", "phpuser", "sesame") or die("Failure to communicate with database");
8 mysql_select_db("test");
9  
10 // If the form has been submitted, record the preference
11 if ($_POST['submit'] == 'Submit') { 
12   if ($_POST['tall'] == 1) { 
Additional matches viewable in cache of PHPBible_2ndEd/ch21/mult_chkbx.php.
PHPBible_2ndEd/ch21/optout.php (67 lines)
2  
3 // Open connection to the database
4 mysql_connect("localhost", "phpuser", "sesame") or die("Failure to communicate with database");
5 mysql_select_db("test");
6  
7 // If the form has been submitted, record the preference and redisplay
8 if ($_POST['submit'] == 'Submit') { 
9   $email = $_POST['email']; 
Additional matches viewable in cache of PHPBible_2ndEd/ch21/optout.php.
PHPBible_2ndEd/ch21/comment_edit.php (72 lines)
2  
3 // Open connection to the database
4 mysql_connect("localhost", "phpuser", "sesame") or die("Failure to communicate with database");
5 mysql_select_db("test");
6  
7 if ($_POST['submit'] == 'Submit') { 
8   // Format the data
9   $comment_id = $_POST['comment_id']; 
10   $comment_header = $_POST['comment_header']; 
Additional matches viewable in cache of PHPBible_2ndEd/ch21/comment_edit.php.
Source code below from:
Web Database Applications with PHP & MySQL
By Hugh E. Williams and David Lane
Published March, 2002
Average rating

      Powells     Alibris

example.6-6.php (119 lines)
2 /* 
3 Source code example for Web Database Applications
4  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 die("Could not connect to database"); 93 94 if (!mysql_select_db($databaseName, $connection)) 95 showerror(); 96 97 // Reassemble the date of birth into database format 98 $dob = " \"$parts[3]-$parts[2]-$parts[1]\""; 99
Additional matches viewable in cache of example.6-6.php.
example.6-8.php (137 lines)
2 /* 
3 Source code example for Web Database Applications
4  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 die("Could not connect to database"); 96 97 if (!mysql_select_db($databaseName, $connection)) 98 showerror(); 99 100 // Reassemble the date of birth into database format 101 $dob = " \"$parts[3]-$parts[2]-$parts[1]\""; 102
Additional matches viewable in cache of example.6-8.php.
example.8-4.php (138 lines)
2 /* 
3 Source code example for Web Database Applications
4  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 showerror(); 93 94 if (!mysql_select_db($databaseName, $connection)) 95 showerror(); 96 97 // Reassemble the date of birth into database format 98 $dob = " \"$parts[3]-$parts[2]-$parts[1]\""; 99
Additional matches viewable in cache of example.8-4.php.
new/example.customer.1.php (386 lines)
2 /* 
3 Source code example for Web Database Applications
4  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246 showerror(); 247 248 if (!mysql_select_db($databaseName, $connection)) 249 showerror(); 250 251 $query = "SELECT * FROM users 252 WHERE user_name = '" . 253 $formVars["email"] . "'"; 254 255 if (!($result = @ mysql_query ($query,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
295 showerror(); 296 297 if (!mysql_select_db($databaseName, $connection)) 298 showerror(); 299 } 300 301 // Reassemble the date of birth into database format 302 $dob = " \"$parts[3]-$parts[2]-$parts[1]\""; 303
Additional matches viewable in cache of new/example.customer.1.php.
new/example.order.3.php (258 lines)
2 /* 
3 Source code example for Web Database Applications
4  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 showerror(); 59 60 if (!mysql_select_db($databaseName, $connection)) 61 showerror(); 62 63 // Several tables must be locked to finalise a purchase. 64 // We avoid locking four other tables by 65 // using another DBMS connection to produce the wine 66 // information 67 $query = "LOCK TABLES inventory WRITE, orders WRITE, items WRITE, 68 users READ, customer READ";
Additional matches viewable in cache of new/example.order.3.php.
Source code below from:
Programming PHP
By Rasmus Lerdorf and Kevin Tatroe
Published March, 2002
Average rating

      Powells     Alibris

progphp-examples/ch08/8-6.php (74 lines)
15 <?php 
16 // Establish the database connection.
17  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 // categories. 32 $sql = "SELECT * FROM categories"; 33 $result = $db->query($sql);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 if (DB::isError($row)) die($row->getMessage()); 37 echo '<tr><td class="formlabel">'; 38 echo "<a href=\"$PHP_SELF?cat_id=$row[0]\">";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47 if ($cat_id) { 48 $sql = "SELECT * FROM businesses b, biz_categories bc where"; 49 $sql .= " category_id = '$cat_id'";

progphp-examples/ch08/display.php (74 lines)
15 <?php 
16 // Establish the database connection.
17  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 // categories. 32 $sql = "SELECT * FROM categories"; 33 $result = $db->query($sql);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 if (DB::isError($row)) die($row->getMessage()); 37 echo '<tr><td class="formlabel">'; 38 echo "<a href=\"$PHP_SELF?cat_id=$row[0]\">";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47 if ($cat_id) { 48 $sql = "SELECT * FROM businesses b, biz_categories bc where"; 49 $sql .= " category_id = '$cat_id'";
Source code below from:
PHP Advanced for the World Wide Web Visual QuickPro Guide
By Larry Ullman
Published 15 December, 2001
Average rating

      Powells     Alibris

3/script_03_02.php (30 lines)
8 <?php # add_author.php 
9  
10 // Connect to the database.
11 $db_connection = mysql_connect ('localhost', 'username', 'password') or die (mysql_error());
12 $db_select = mysql_select_db('larrys_books') or die (mysql_error());
13  
14 // If the form was submitted, process it.
15 if (isset($submit)) { 
16     $query = "insert into authors values ('0', '$last_name', '$first_name')"; 
Additional matches viewable in cache of 3/script_03_02.php.
3/script_03_06.php (27 lines)
9  
10 // Connect to the database.
11 $db_connection = mysql_connect ('localhost', 'username', 'password') or die (mysql_error());
12 $db_select = mysql_select_db('larrys_books') or die (mysql_error());
13  
14 // Query the database.
15 $query = "SELECT books.title, books.author_id, formats.format, books.call_number, books.signed, books.notes, DATE_FORMAT(books.date_entered, '%M %e, %Y') AS de, CONCAT(authors.first_name, ' ', authors.last_name) AS author FROM books, authors, formats WHERE books.book_id = '$bid' AND authors.author_id = books.author_id AND formats.format_id = books.format_id";
16 $query_result = @mysql_query ($query); 
17 $row = @mysql_fetch_array ($query_result); 
Additional matches viewable in cache of 3/script_03_06.php.
3/script_03_03.php (59 lines)
8 <?php # add_book.php 
9  
10 // Connect to the database.
11  
12 $db_connection = mysql_connect ('localhost', 'username', 'password') or die (mysql_error());
13 $db_select = mysql_select_db('larrys_books') or die (mysql_error());
14  
15 // If the form was submitted, process it.
16 if (isset($submit)) { 
17     $query = "insert into books values ('0', '$title', '$author_id', '$format_id', '$call_number', '$notes', NOW(), '$signed')";
Additional matches viewable in cache of 3/script_03_03.php.
5/script_05_01.inc (20 lines)
11 // Base url = http://www.community.com 
12  
13 // Database-specific information:
14 $db_info[username] = "username"; 
15 $db_info[password] = "password"; 
16 $db_info[host] = "localhost"; 
17 $db_info[dbname] = "community"; 
18 $db_connection = mysql_connect ($db_info[host], $db_info[username], $db_info[password]) or die (mysql_error());;
19 mysql_select_db ($db_info[dbname], $db_connection) or die (mysql_error());
20 ?> 

6/script_06_01.inc (20 lines)
11 // Base url = http://www.waponiwoo.com 
12  
13 // Database-specific information:
14 $db_info[username] = "username"; 
15 $db_info[password] = "password"; 
16 $db_info[host] = "localhost"; 
17 $db_info[dbname] = "waponi_woo"; 
18 $db_connection = mysql_connect ($db_info[host], $db_info[username], $db_info[password]) or die (mysql_error());
19 mysql_select_db ($db_info[dbname], $db_connection) or die (mysql_error());
20 ?> 
Source code below from:
Foundation PHP for Flash
By Steve Webster
Published September, 2001
Average rating

      Powells     Alibris

phpforflash/chapter10/common.php (62 lines)
4  
5 // Database details
6 $dbHost = "localhost"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 /********************************************************* 16 ** Function: dbconnect() ** 17 ** Desc: Perform database server connection and ** 18 ** database selection operations ** 19 *********************************************************/ 20 function dbConnect() {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 // If connection failed... 31 if (!$link) { 32 // Inform Flash of error and quit 33 fail("Couldn't connect to database server"); 34 } 35 36 // Attempt to select our database. If failed... 37 if (!@mysql_select_db($dbName)) { 38 // Inform Flash of error and quit
Additional matches viewable in cache of phpforflash/chapter10/common.php.
phpforflash/chapter11/common.php (62 lines)
4  
5 // Database details
6 $dbHost = ""; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 /********************************************************* 16 ** Function: dbconnect() ** 17 ** Desc: Perform database server connection and ** 18 ** database selection operations ** 19 *********************************************************/ 20 function dbConnect() {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 // If connection failed... 31 if (!$link) { 32 // Inform Flash of error and quit 33 fail("Couldn't connect to database server"); 34 } 35 36 // Attempt to select our database. If failed... 37 if (!@mysql_select_db($dbName)) { 38 // Inform Flash of error and quit
Additional matches viewable in cache of phpforflash/chapter11/common.php.
phpforflash/chapter12/common.php (108 lines)
4  
5 // Database details
6 $dbHost = ""; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 /********************************************************* 15 ** Function: dbconnect() ** 16 ** Desc: Perform database server connection and ** 17 ** database selection operations ** 18 *********************************************************/ 19 function dbConnect() {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 // If connection failed... 30 if (!$link) { 31 // Inform Flash of error and quit 32 fail("Couldn't connect to database server"); 33 } 34 35 // Attempt to select our database. If failed... 36 if (!@mysql_select_db($dbName)) { 37 // Inform Flash of error and quit
Additional matches viewable in cache of phpforflash/chapter12/common.php.
phpforflash/chapter3/common.php (93 lines)
4  
5 // Database details
6 $dbHost = "localhost"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 /********************************************************* 15 ** Function: dbconnect() ** 16 ** Desc: Perform database server connection and ** 17 ** database selection operations ** 18 *********************************************************/ 19 function dbConnect() {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 // If connection failed... 30 if (!$link) { 31 // Inform Flash of error and quit 32 fail("Couldn't connect to database server"); 33 } 34 35 // Attempt to select our database. If failed... 36 if (!@mysql_select_db($dbName)) { 37 // Inform Flash of error and quit
Additional matches viewable in cache of phpforflash/chapter3/common.php.
phpforflash/chapter9/select_db.php (26 lines)
1 <? 
2 // Attempt to connect to the MySQL server
3 $link = @mysql_connect("localhost", "", "");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 // If the connection was unsuccessful... 6 if (!$link) { 7 // Output error information and exit 8 print "Error connecting to database server"; 9 exit; 10 } 11 12 // Attempt to select database. If successfulÖ 13 if (@mysql_select_db("phpforflash")) { 14 // Inform user of success 15 print "Database selected"; 16 } else { 17 // Otherwise inform user of failure 18 print "Couldn't select database"; 19 } 20 21 // Close the connection 22 mysql_close($link); 23 ?>

Not satisfied? Try this search biased towards software and programming:
Google