Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14830

Re: mysql_connect statement not connecting to database

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Matthew Carter <m@ahungry.com>
Newsgroups comp.lang.php
Subject Re: mysql_connect statement not connecting to database
Date Thu, 15 Jan 2015 14:43:43 -0500
Organization Ahungry (http://ahungry.com)
Lines 80
Message-ID <87k30nzv68.fsf@ahungry.com> (permalink)
References <66710953-7d91-407e-8589-b919c0adba6a@googlegroups.com> <5602796.CH6WsXFhKx@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Info mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="5882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/I2Lt715lhpZSZVxgHD6kT"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock sha1:6mLfCx/E3KFHAHVqMW+4Jhuz5yU= sha1:Y7Z5JG5bSCbLOjI/dzxl9VfbLmw=
Xref csiph.com comp.lang.php:14830

Show key headers only | View raw


Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> mcghepa@gmail.com wrote:
>
>> […]  I am using apache webserver.  When I run a php script through 
>> localhost through my browser the script works well.  When I run my 
>> mysql_connect.php then all I get is a blank page.  nothing happens. I 
>> placed an echo statement at the end to verify that it connected.
>> The echo statement doesn't appear when I refresh the page.
>
> The “echo” statement is not supposed to appear.  Perhaps you mean that the 
> output it is supposed to generate does not appear.
>
> [code reformatted to 80 columns]
>> <?php //# Script 7.2 - mysql_connect.php
>> 
>> // This file contains the database access information.
>> // This file also establishes a connection to MySQL and selects the
>> // database.
>> 
>> // Set the database access information as constants.
>> DEFINE ('DB_USER', 'root');
>   ^^^^^^
>> DEFINE ('DB_PASSWORD', 'pass@word1');
>> DEFINE ('DB_HOST', 'localhost:3306');
>> DEFINE ('DB_NAME', 'reg');
>> 
>> // Make the connnection.
>> $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) OR 
>                                                         ^^
>> die ('Could not connect to MySQL: ' . mysql_error() );
>> 
>> // Select the database.
>> @mysqli_select_db(DB_NAME) OR die ('Could not select the database: ' .
>                              ^^
>> mysql_error() );
>
> It is not a good idea to write the identifiers of functions or operators in 
> all-uppercase.  This style should be reserved for constants.
>
> It is also not a good idea to let the opening parenthesis of a function call 
> be preceded by whitespace.  This style should be reserved for control 
> statements like “if”.
>
>> echo 'hello';
>> ?>
>
> You can and should omit the “?>” except when you want to leave PHP parsing 
> mode to output something (usually in templates only).
>
> Debugging is easier if you do not suppress the messages that code generates.  
> So, for now, you should remove the “@”s, and run
>
>   ini_set('display_errors', true);
>   error_reporting(E_ALL | E_STRICT);
>
> before all other statements.  This should be the default for your local 
> (development) server, though; edit php.ini if necessary (all recommended 
> development values are in the comments of a default distribution).
>
> If that still does not help, make sure that the “mysqli” PHP module is 
> loaded.  You can use phpinfo() for that.
>
> Because a Parse Error or a Fatal Error is required for execution not to 
> reach the “echo” statement.  This could be either a syntax error or you 
> could have attempted to call a function that was not defined, respectively.  
> I can see no obvious syntax error in the posted code (although your code 
> lines are too long to be easily readable; consider wrapping at column 80 at 
> the latest, at least for Usenet) which leaves only the second possibility.

GNU style indentation does require a space before the parenthesis (even
for a function call), although I'd imagine there are few GNU based
PHP projects.

Looking at how its completely inconsistent though, I don't think this
was GNU style indentation (my personal favorite actually).

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

mysql_connect statement not connecting to database mcghepa@gmail.com - 2015-01-15 08:21 -0800
  Re: mysql_connect statement not connecting to database Matthew Carter <m@ahungry.com> - 2015-01-15 11:49 -0500
  Re: mysql_connect statement not connecting to database Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-15 18:01 +0100
    Re: mysql_connect statement not connecting to database Matthew Carter <m@ahungry.com> - 2015-01-15 14:43 -0500
      Re: mysql_connect statement not connecting to database Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-17 15:48 +0100
        Indent style (was: mysql_connect statement not connecting to database) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-17 18:13 +0100
          Re: Indent style Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-17 19:08 +0100
            Re: Indent style "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-22 14:22 +0100
    Re: mysql_connect statement not connecting to database richard <noreply@example.com> - 2015-01-16 00:10 -0500
      Re: mysql_connect statement not connecting to database Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-16 10:03 +0000

csiph-web