Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:20:25+00:00 2026-05-24T12:20:25+00:00

I am running a MySQL database with Mac OS X Lion Server. I have

  • 0

I am running a MySQL database with Mac OS X Lion Server. I have a PHP script running on my server that wants to access a database. The PHP script is here:

/Library/Server/Web/Data/Sites/Default

The database is here:

/usr/local/mysql

How do I get the PHP script to access the database if they are not in the same directory (the database is above it). Thanks for your help!

Here is the error I am experiencing:

Connect failed: No such file or directory?There seems to have been a  slight problem with our database, please try again later.<br /><br />? <textarea rows="10" cols="80">MySQL Error:???42??Error: ?Error #: ?  Filename:

And in my PHP file, this is the code I use to access the database:

$this->DB_HOST = '67.85.14.141';
$this->DB_USERNAME = 'username';
$this->DB_PASSWORD = 'password';
$this->DB_DATABASE = 'Carillons';

Rest of code below:

/**
 * Begin Document
 */

class DbConnect
{
/**
* Connection to MySQL.
*
* @var string
*/
var $link;

/**
* Holds the most recent connection.
*
* @var string
*/
var $recent_link = null;

/**
* Holds the contents of the most recent SQL query.
*
* @var string
*/
var $sql = '';

/**
* Holds the number of queries executed.
*
* @var integer
*/
var $query_count = 0;

/**
* The text of the most recent database error message.
*
* @var string
*/
var $error = '';

/**
* The error number of the most recent database error message.
*
* @var integer
*/
var $errno = '';

/**
* Do we currently have a lock in place?
*
* @var boolean
*/
var $is_locked = false;

/**
* Show errors? If set to true, the error message/sql is displayed.
*
* @var boolean
*/
var $show_errors = false;

/**
* Log errors? If set to true, the error message/sql is logged.
*
* @var boolean
*/
public $log_errors = false;

/**
* The Database.
*
* @var string
*/
public $DB_DATABASE;

/**
* The variable used to contain a singleton instance of the database connection.
*
* @var string
*/
static $instance;

/**
* The number of rows affected by the most recent query.
*
* @var string
*/
public $affected_rows;

public $insert_id;



/**
* Constructor. Initializes a database connection and selects our database.
*/
function __construct()
{
    $this->DB_HOST     = '67.85.14.141';
    $this->DB_USERNAME = 'username'; // !!! CHANGE ME
    $this->DB_PASSWORD = 'password'; // !!! CHANGE ME
    $this->DB_DATABASE = 'Carillons'; // !!! CHANGE ME
}

/**
* Singleton pattern to retrieve database connection.
*
* @return mixed MySQL database connection
*/
function _get($property)
{
    if(self::$instance == NULL)
    {
        self::$instance = $this->connect();
    }

    return self::$instance->$property;

}


/**
* Singleton pattern to retrieve database connection.
*
* @return mixed MySQL database connection
*/
function Connection()
{
    if(self::$instance == NULL)
    {
        self::$instance = $this->connect();
    }
    return self::$instance;
}


/**
* Connect to the Database.
*
*/
function connect()
{
    self::$instance = new mysqli($this->DB_HOST, $this->DB_USERNAME, $this->DB_PASSWORD, $this->DB_DATABASE);

    if (mysqli_connect_errno()) {
        $this->raise_error(printf("Connect failed: %s\n", mysqli_connect_error()));
    }

    return self::$instance;
}


/**
* Executes a sql query. If optional $only_first is set to true, it will
* return the first row of the result as an array.
*
* @param  string  Query to run
* @param  bool    Return only the first row, as an array?
* @return mixed
*/
function query($sql, $only_first = false)
{
    if(self::$instance == NULL)
    {
        self::$instance = $this->connect();
    }

    $this->recent_link =& self::$instance;
    $this->sql =& $sql;

    if(!$result = self::$instance->query($sql))
    {
        $this->raise_error(printf("Connect failed: %s\n", self::$instance->error));
    }

    $this->affected_rows = self::$instance->affected_rows;
    $this->insert_id = self::$instance->insert_id;
    $this->query_count++;

    if ($only_first)
    {
        $return = $result->fetch_array(MYSQLI_ASSOC);
        $this->free_result($result);
        return $return;
    }
    return $result;
}

/**
* Fetches a row from a query result and returns the values from that row as an array.
*
* @param  string  The query result we are dealing with.
* @return array
*/
function fetch_array($result)
{
    return @mysql_fetch_assoc($result);
}

/**
* Returns the number of rows in a result set.
*
* @param  string  The query result we are dealing with.
* @return integer
*/
function num_rows($result)
{
    return self::$instance->num_rows;
}

/**
* Retuns the number of rows affected by the most recent query
*
* @return integer
*/
function affected_rows()
{
    return self::$instance->affected_rows;
}


/**
* Returns the number of queries executed.
*
* @param  none
* @return integer
*/
function num_queries()
{
    return $this->query_count;
}

/**
* Lock database tables
*
* @param   array  Array of table => lock type
* @return  void
*/
function lock($tables)
{
    if (is_array($tables) AND count($tables))
    {
        $sql = '';

        foreach ($tables AS $name => $type)
        {
            $sql .= (!empty($sql) ? ', ' : '') . "$name $type";
        }

        $this->query("LOCK TABLES $sql");
        $this->is_locked = true;
    }
}

/**
* Unlock tables
*/
function unlock()
{
    if ($this->is_locked)
    {
        $this->query("UNLOCK TABLES");
    }
}

/**
* Returns the ID of the most recently inserted item in an auto_increment field
*
* @return  integer
*/
function insert_id()
{
    return self::$instance->insert_id;
}

/**
* Escapes a value to make it safe for using in queries.
*
* @param  string  Value to be escaped
* @param  bool    Do we need to escape this string for a LIKE statement?
* @return string
*/
function prepare($value, $do_like = false)
{
    if(self::$instance == NULL)
    {
        self::$instance = $this->connect();
    }

    if ($do_like)
    {
        $value = str_replace(array('%', '_'), array('\%', '\_'), $value);
    }

    return self::$instance->real_escape_string($value);
}

/**
* Frees memory associated with a query result.
*
* @param  string   The query result we are dealing with.
* @return boolean
*/
function free_result($result)
{
    return @mysql_free_result($result);
}

/**
* Turns database error reporting on
*/
function show_errors()
{
    $this->show_errors = true;
}

/**
* Turns database error reporting off
*/
function hide_errors()
{
    $this->show_errors = false;
}

/**
* Closes our connection to MySQL.
*
* @param  none
* @return boolean
*/
function close()
{
    $this->sql = '';
    return self::$instance->close();
}

/**
* Returns the MySQL error message.
*
* @param  none
* @return string
*/
function error()
{
    $this->error = (is_null($this->recent_link)) ? '' : self::$instance->error; 
    return $this->error;
}

/**
* Returns the MySQL error number.
*
* @param  none
* @return string
*/
function errno()
{
    $this->errno = (is_null($this->recent_link)) ? 0 : self::$instance->errno ;
    return $this->errno;
}

/**
* Gets the url/path of where we are when a MySQL error occurs.
*
* @access private
* @param  none
* @return string
*/
function _get_error_path()
{
    if ($_SERVER['REQUEST_URI'])
    {
        $errorpath = $_SERVER['REQUEST_URI'];
    }
    else
    {
        if ($_SERVER['PATH_INFO'])
        {
            $errorpath = $_SERVER['PATH_INFO'];
        }
        else
        {
            $errorpath = $_SERVER['PHP_SELF'];
        }

        if ($_SERVER['QUERY_STRING'])
        {
            $errorpath .= '?' . $_SERVER['QUERY_STRING'];
        }
    }

    if (($pos = strpos($errorpath, '?')) !== false)
    {
        $errorpath = urldecode(substr($errorpath, 0, $pos)) . substr($errorpath, $pos);
    }
    else
    {
        $errorpath = urldecode($errorpath);
    }
    return $_SERVER['HTTP_HOST'] . $errorpath;
}

/**
* If there is a database error, the script will be stopped and an error message displayed.
*
* @param  string  The error message. If empty, one will be built with $this->sql.
* @return string
*/
function raise_error($error_message = '')
{
    if ($this->recent_link)
    {
        $this->error = $this->error($this->recent_link);
        $this->errno = $this->errno($this->recent_link);
    }

    if ($error_message == '')
    {
        $this->sql = "Error in SQL query:\n\n" . rtrim($this->sql) . ';';
        $error_message =& $this->sql;
    }
    else
    {
        $error_message = $error_message . ($this->sql != '' ? "\n\nSQL:" . rtrim($this->sql) . ';' : '');
    }

    $message = "<textarea rows=\"10\" cols=\"80\">MySQL Error:\n\n\n$error_message\n\nError: {$this->error}\nError #: {$this->errno}\nFilename: " . $this->_get_error_path() . "\n</textarea>";

    if (!$this->show_errors)
    {
        $message = "<!--\n\n$message\n\n-->";
    }
    else die("There seems to have been a slight problem with our database, please try again later.<br /><br />\n$message");
}
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:20:26+00:00Added an answer on May 24, 2026 at 12:20 pm

    MySQL is not accessed based on files.

    As long as it is running you just need the server name username and password to the mysql databse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in a MySQL database that I am running simple SELECT
My php code fails to connect to the mysql database on my web server.
We have a Linux server that has been running our MySQL 5.1 server. For
I'm using Subsonic 3.0.0.3 with ActiveRecord, running against a MySQL database. I'm finding that
I have a mysql database filled up and running on a Windows computer, is
We are running a PHP (zend framework) app that creates a database per user
I have a database in data center, which is running MySQL, and I want
I work on a Joomla web site, installed on a MySQL database and running
So the scenario is this: I have a mySQL database on a local server
I have a MYSQL database which needs to be accessed by both PHP and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.