Re: [PHP] PHP and MYSQL don't shake hands

2003-09-18 Thread CPT John W. Holmes
From: Frank Tudor [EMAIL PROTECTED]

 The problem I am having is that when I try to pass values to the
 database the php fails.
 
 I think I have singled it down to the connection string but I am
 not sure.
[snip]
 function db_connect() {
global $dbhost, $dbusername, $dbuserpassword,
 $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
 
$link_id = mysql_connect($dbhost, $dbusername,
 $dbuserpassword);
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;
 }
 ?
 
 My php sample code:::
 
 ?php
 //db_connect.php
 include common_db.inc;
 error_reporting(0);

Take this out or set it to E_ALL while debugging.

 $link_id = db_connect();
 if(!$link_id) die(sql_error());

Use

$link_id = db_connect() or die(sql_error());

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP and MYSQL don't shake hands

2003-09-18 Thread Frank Tudor
Guys,

I have moved from a foxserv(apache, php, mysql, all in one
install tool) windows test environment to a Linux apache php
mysql setup specifically mandrake linux production server.

The problem I am having is that when I try to pass values to the
database the php fails.

I think I have singled it down to the connection string but I am
not sure.

basically, I have tested the sample code in the book 'beginning
php' by (wrox).

I have made no changes.

I think that the dbhost is the problem.

when I look at the phpinfo page it shows me not localhost but a
'name.com'

so I try $dbhost = 'name.com';

and then i also try $dbhost = 'localhost';

and neither seem to work.

Can anyone tell me what I'm doing wrong?

Here is my sample code:

My db connect include file::

?php
//common_db.inc
$dbhost = 'localhost';
$dbusername = 'name';
$dbuserpassword = 'pass';
$default_dbname = 'test';

$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);
   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;
}
?

My php sample code:::

?php
//db_connect.php
include common_db.inc;
error_reporting(0);

$link_id = db_connect();
if(!$link_id) die(sql_error());
else echo Successfully made a connection to $dbhost.BR;
?

My error is a white screen

and this is simple code out of the book.

Could it be my dbhost is incorrect. I checked my services and
Mysql is running.

Apache running and parsing other php pages that don't do a db
connect so I'm pretty sure it's the db connect stuff.

Thanks,
Frank

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php