Re: mysql_connect() Help
| From: | Matt Anderton | Date: | Sun, 09 Mar 2008 01:22:01 +0000 |
| Subject: | Re: mysql_connect() Help | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44724@lists.php.net to get a copy of this message | ||
Manysh -- maybe you missed the MySQL extension installation?
2nd or 3rd screen in the setup process there is a list of extensions -- none
of them are installed by default.
Your manual method of creating the 'ext' directory is a step in the right
direction, but you probably have a missing directive or two in your php.ini.
something like...
[PHP_MYSQL]
extension=php_mysql.dll
but there may be some other directives you are missing - port numbers, etc.
best to just reinstall.
-- matt
On Sat, Mar 8, 2008 at 5:53 PM, Manysh <geminish@gmail.com> wrote:
> Thanks for your input, Jon. Few more observations...
>
> Yes, I have PHP+Apache+MySQL installed for private use. I am just
> trying to connect to the database successfully first and will create
> other users when I make a successful connection. I made the changes as
> below and still cannot connect to the database. The echo "After
> connecting to the database..." is not in an if statement. I modified
> the script to make it real simple for me....
>
> I found this document:
> http://www.artfulsoftware.com/php_mysql_win.html which outlines
> installation and configuration steps for MySQL and PHP. Unfortunately,
> I can't get it to work. One thing I noticed is that my PHP
> inatallation didn't have any "ext" directory so I manually created one
> and copied php_mysqli.dll to this directory and restarted my computer.
> It didn't work still. Any comments/ideas?
> ----
> <?php
> /*--------- DATABASE CONNECTION INFO---------*/
> $hostname="localhost";
> $mysql_login="admin";
> $mysql_password="admin";
>
> echo "Connected successfully yet? Probably not.";
>
> $link = @mysql_connect($hostname,$mysql_login,$mysql_password);
> if (!$link) {
> //die('Could not connect: ' . mysql_error());
> echo "Some problem here....";
> }
> else
> echo "Connected?";
>
> $dbname = 'sampleapp';
> $dbselect = @mysql_select_db($dbname);
>
> if ($dbselect)
> echo "Connected to the database";
> else
> echo "Still not connected to the database";
> mysql_close($link);
> ?>
> ----
>
>
>
>
>
> On Sat, Mar 8, 2008 at 3:07 PM, Jon L. <jonllmsed@gmail.com> wrote:
> > Since you seem to want to handle the errors yourself, you may try using
> the
> > @ operator on the mysql functions.
> > It'll silence any errors or warning that the functions might usually
> > generate; but, of course, you'll be left to test for errors yourself.
> >
> >
> > $link = @mysql_connect($hostname,$mysql_login,$mysql_password);
> >
> > @mysql_select_db($dbname);
> >
> > With that, the following statement should return any errors that MySQL
> would
> > otherwise generate:
> >
> >
> > if (!$link) {
> > die (mysql_error());
> > }
> >
> >
> > Now, I don't see any reason for the 2nd echo (i.e., echo " After
> connecting
> > to the database...";) to not be called.
> > Is it in an if statement or other structure/scope in your actual script?
> >
> > However, I do see a reason for another to never be called:
> >
> >
> > if (!$link) {
> > die('Could not connect: ' . mysql_error());
> > echo "Some problem here....";
> > }
> >
> > Once you call die, script execution discontinues.
> > The echo after it will never be called, either by !$link returning false
> to
> > if or by die being called first.
> >
> >
> > On another note...
> > This sounds like you have PHP & MySQL installed for private use.
> > But, even if that's the case, I don't recommend connecting to the admin
> > account unless you really need to.
> >
> > You should check out the following page on adding users:
> > http://dev.mysql.com/doc/refman/5.0/en/adding-users.html
> >
> > And read up on the following commands:
> > CREATE USER:
> > http://dev.mysql.com/doc/refman/5.0/en/create-user.html
> > GRANT: http://dev.mysql.com/doc/refman/5.0/en/grant.html
> >
> > - Jon L.
> >
> >
> >
> > On Sat, Mar 8, 2008 at 1:36 PM, Manysh <geminish@gmail.com> wrote:
> > >
> > >
> > >
> > > Hi,
> > >
> > > I am trying to make a connection to the MySQL database from PHP but it
> > > seems like I am missing a step or something and hence cannot connect
> > > to the database. I have tried everything but I can't figure out why.
> > > Please suggest/help (I am a beginner in PHP/MySQL/Apache).
> > >
> > > I am using MySQL 5.0.51a-community-nt on my Windows XP machine. PHP
> > > version used is 5.2 and Apache version is 2.2.
> > >
> > > Code Snippet:
> > >
> > > $hostname="localhost";
> > > $mysql_login="admin";
> > > $mysql_password="admin";
> > > //$database="sampleapp";
> > >
> > > echo "Print this..."; // THIS MESSAGE IS PRINTED
> > >
> > > $link = mysql_connect($hostname,$mysql_login,$mysql_password);
> > >
> > > echo " After connecting to the database..."; // THIS DOES NOT PRINT
> > > if (!$link) {
> > > die (mysql_error()); // NOR THIS ONE
> > > }
> > >
> > > $dbname = 'sampleapp';
> > > mysql_select_db($dbname);
> > >
> > > echo $link;
> > >
> > > if (!$link) {
> > > die('Could not connect: ' . mysql_error());
> > > echo "Some problem here....";
> > > }
> > > //echo 'Connected successfully';
> > > mysql_close($link);
> > > ?>
> > >
> > > Any help is appreciated.
> > > Thanks,
> > > Manysh
> > >
> > > --
> > > PHP Database Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>