Hi
New to PHP accessing MySQL and getting a blank Web page. This is my first attempt to access data and looking for a good way to do so. This is code from two books. If you have examples, Web site or code, that work can you let me know
Thanks
***** PDP Code:
<?php
//common_db.inc
// Code from Beginning PHP4 p.402
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpassword = 'hawk';
$default_dbname = 'phpuser';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
// Code from Wrow - Beginning Databases with MySQL Start
// p.387 - 388
$query = "select * from access_log;";
$result_set = msql_quert($query) or die ("Query failed\n");
echo "<P>We have had " . mysql_num_row($result_set) . "patrons so far.";
// Code from Wrow - Beginning Databases with MySQL End
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
?>
*** Access.log reads:******************************
127.0.0.1 - - [16/Oct/2007:05:33:19 -0400] "GET /test/ccommon_db.php HTTP/1.1" 200 -
127.0.0.1 - - [16/Oct/2007:05:34:34 -0400] "GET /test/ccommon_db.php HTTP/1.1" 200 -
*** Error Log reads:**********************************
C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Test\\ccommon_db.php on line 21, referer: [Tue Oct 16 05:31:31 2007] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Test\\ccommon_db.php on line 21, referer:
New to PHP accessing MySQL and getting a blank Web page. This is my first attempt to access data and looking for a good way to do so. This is code from two books. If you have examples, Web site or code, that work can you let me know
Thanks
***** PDP Code:
<?php
//common_db.inc
// Code from Beginning PHP4 p.402
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpassword = 'hawk';
$default_dbname = 'phpuser';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
// Code from Wrow - Beginning Databases with MySQL Start
// p.387 - 388
$query = "select * from access_log;";
$result_set = msql_quert($query) or die ("Query failed\n");
echo "<P>We have had " . mysql_num_row($result_set) . "patrons so far.";
// Code from Wrow - Beginning Databases with MySQL End
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
?>
*** Access.log reads:******************************
127.0.0.1 - - [16/Oct/2007:05:33:19 -0400] "GET /test/ccommon_db.php HTTP/1.1" 200 -
127.0.0.1 - - [16/Oct/2007:05:34:34 -0400] "GET /test/ccommon_db.php HTTP/1.1" 200 -
*** Error Log reads:**********************************
C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Test\\ccommon_db.php on line 21, referer: [Tue Oct 16 05:31:31 2007] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Test\\ccommon_db.php on line 21, referer: