Re: PHP and MYSQL don't shake hands
| From: | CPT John W. Holmes | Date: | Thu, 18 Sep 2003 18:21:19 +0000 |
| Subject: | Re: PHP and MYSQL don't shake hands | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163040@lists.php.net to get a copy of this message | ||
From: "Frank Tudor" <frank_tudor@yahoo.com>
> 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());