Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Matthew Carter Newsgroups: comp.lang.php Subject: Re: mysql_connect statement not connecting to database Date: Thu, 15 Jan 2015 11:49:18 -0500 Organization: Ahungry (http://ahungry.com) Lines: 41 Message-ID: <87oaq0yooh.fsf@ahungry.com> References: <66710953-7d91-407e-8589-b919c0adba6a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="25308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MTdUH00bClrCJ2RkA0fUg" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:OmzvCfypRfo5Gt4aSl5du2kzh7Y= sha1:qT9ozSHiX/OB2liPNqUXzd0NUzw= Xref: csiph.com comp.lang.php:14828 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. > > > > // 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