Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14827 > unrolled thread
| Started by | mcghepa@gmail.com |
|---|---|
| First post | 2015-01-15 08:21 -0800 |
| Last post | 2015-01-16 10:03 +0000 |
| Articles | 10 — 6 participants |
Back to article view | Back to comp.lang.php
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
| From | mcghepa@gmail.com |
|---|---|
| Date | 2015-01-15 08:21 -0800 |
| Subject | mysql_connect statement not connecting to database |
| Message-ID | <66710953-7d91-407e-8589-b919c0adba6a@googlegroups.com> |
I am attempting to try and connect to my mysql database. 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.
<?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() );
echo 'hello';
?>
[toc] | [next] | [standalone]
| From | Matthew Carter <m@ahungry.com> |
|---|---|
| Date | 2015-01-15 11:49 -0500 |
| Message-ID | <87oaq0yooh.fsf@ahungry.com> |
| In reply to | #14827 |
mcghepa@gmail.com writes:
> I am attempting to try and connect to my mysql database. 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.
>
>
> <?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() );
>
> echo 'hello'; ?>
The '@' suppresses error output, try removing and see what you get.
Does the command line work with those credentials for connecting?
mysql -h localhost:3306 -u root -p'pass@word1'
If that does connect from the CLI, when you do a SHOW TABLES do you see
'reg' listed?
Could be a permissions error with your mysql user or incorrect info.
--
Matthew Carter (m@ahungry.com)
http://ahungry.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-01-15 18:01 +0100 |
| Message-ID | <5602796.CH6WsXFhKx@PointedEars.de> |
| In reply to | #14827 |
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.
--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Matthew Carter <m@ahungry.com> |
|---|---|
| Date | 2015-01-15 14:43 -0500 |
| Message-ID | <87k30nzv68.fsf@ahungry.com> |
| In reply to | #14829 |
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
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-01-17 15:48 +0100 |
| Message-ID | <1879834.QDGmRacGsM@PointedEars.de> |
| In reply to | #14830 |
Matthew Carter wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >> 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”. >> […] > > 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. My experience (15 years with PHP now) and recent research indicates that GNU Style is unheard of in the greater PHP developer community. PHP coding styles include, in no particular order, and not exhaustive: - PEAR and PEAR2 Coding Standards <http://pear.php.net/manual/en/coding-standards.php> - PHP Standard Recommendations PSR-1, PSR-2, and PSR-4 (deprecates PSR-0) <https://github.com/php-fig/fig-standards/tree/master/accepted> - Symfony Coding Standards (“follows the standards defined in the PSR-0, PSR-1 and PSR-2 documents”) <http://symfony.com/doc/current/contributing/code/standards.html> - Drupal Coding Standards (“loosely based on the PEAR Coding Standards”) <https://www.drupal.org/coding-standards> - WordPress PHP Coding Standards (“similar to Pear standards in many ways, but differ in some key respects”) <https://make.wordpress.org/core/handbook/coding-standards/php/> - Zend Framework Coding Standard for PHP: currently <http://framework.zend.com/manual/1.12/en/coding-standard.html> (no Coding Standard has been published for ZF2 yet, so we can assume that also applies for ZF2 code) - Moodle Coding Style <https://docs.moodle.org/dev/Coding_style> (all retrieved as of the date of this posting) > Looking at how its completely inconsistent though, I don't think this > was GNU style indentation (my personal favorite actually). I could live with GNU Style¹ if it would not make it so hard to tell function/method calls apart. (I prefer Allman style [ibd.] except for expressions, and I have started to insert the space before parameter lists in declarations, to tell them apart from calls.) Please trim your quotes to the relevant minimum. In particular, full quotes are not acceptable. <https://www.netmeister.org/news/learn2quote.html> _________ ¹ <https://en.wikipedia.org/wiki/Indent_style#GNU_style> -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2015-01-17 18:13 +0100 |
| Subject | Indent style (was: mysql_connect statement not connecting to database) |
| Message-ID | <m9e57l$n2b$1@solani.org> |
| In reply to | #14833 |
Thomas 'PointedEars' Lahn wrote: > I could live with GNU Style¹ if it would not make it so hard to tell > function/method calls apart. (I prefer Allman style [ibd.] except for > expressions, and I have started to insert the space before parameter lists in declarations, to tell them apart from calls.) Wouldn't your former Allman style variation be 1TBS[ibd.]? > _________ > ¹ <https://en.wikipedia.org/wiki/Indent_style#GNU_style> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-01-17 19:08 +0100 |
| Subject | Re: Indent style |
| Message-ID | <2217729.AVvK8bdUBl@PointedEars.de> |
| In reply to | #14834 |
Christoph M. Becker wrote: > Thomas 'PointedEars' Lahn wrote: >> I could live with GNU Style¹ if it would not make it so hard to tell >> function/method calls apart. (I prefer Allman style [ibd.] except for >> expressions, and I have started to insert the space before parameter >> lists in declarations, to tell them apart from calls.) > > Wouldn't your former Allman style variation be 1TBS[ibd.]? Yes, it would not, because 1TBS requires that the opening brace is written on the same line as the declaration/control statement, while Allman style requires that it is written one line below it, starting in the same column. 1TBS also makes no statement as to whether declarations should be written differently than calls with regard to whitespace; given that it is described as a variant of K&R style, and in the K&R example the formal parameter list is not preceded by whitespace, it appears not to make such one. >> ¹ <https://en.wikipedia.org/wiki/Indent_style#GNU_style> -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2015-01-22 14:22 +0100 |
| Subject | Re: Indent style |
| Message-ID | <m9qti1$8ok$1@solani.org> |
| In reply to | #14835 |
Thomas 'PointedEars' Lahn wrote:
> Christoph M. Becker wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> I could live with GNU Style¹ if it would not make it so hard to tell
>>> function/method calls apart. (I prefer Allman style [ibd.] except for
>>> expressions, and I have started to insert the space before parameter
^^^^^^^^^^^
>>> lists in declarations, to tell them apart from calls.)
>>
>> Wouldn't your former Allman style variation be 1TBS[ibd.]?
>
> Yes, it would not, because 1TBS requires that the opening brace is written
> on the same line as the declaration/control statement, while Allman style
> requires that it is written one line below it, starting in the same column.
Oops! I've mixed up expressions and statements.
>>> ¹ <https://en.wikipedia.org/wiki/Indent_style#GNU_style>
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2015-01-16 00:10 -0500 |
| Message-ID | <wduvnxqz9moj.1ctcn5u9pg21c.dlg@40tude.net> |
| In reply to | #14829 |
On Thu, 15 Jan 2015 18:01:30 +0100, Thomas 'PointedEars' Lahn wrote:
> 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.
$mysqli = new mysqli("localhost", "user", "pass", "DBname");
In the connect string you forgot to include DBname.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-01-16 10:03 +0000 |
| Message-ID | <m9anm6$s9n$3@dont-email.me> |
| In reply to | #14831 |
On Fri, 16 Jan 2015 00:10:52 -0500, richard wrote:
> $mysqli = new mysqli("localhost", "user", "pass", "DBname");
> In the connect string you forgot to include DBname.
richard bullshit strikes again!
The DBname parameter to mysqli_connect is optional.
How many times do we have to tell you not to answer questions because all
you ever do is expose your absolute ignorance of the subject matter.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web