mysql_connect() Help
am 08.03.2008 20:36:16 von Manysh
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
Re: mysql_connect() Help
am 08.03.2008 22:07:10 von jonllmsed
------=_Part_771_7724851.1205010430081
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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 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
>
>
------=_Part_771_7724851.1205010430081--
Re: mysql_connect() Help
am 09.03.2008 00:53:37 von Manysh
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?
----
/*--------- 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. 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 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
Re: mysql_connect() Help
am 09.03.2008 02:22:01 von Matt Anderton
------=_Part_5279_15130615.1205025721210
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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 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?
> ----
>
> /*--------- 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. 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 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
>
>
------=_Part_5279_15130615.1205025721210--
Re: mysql_connect() Help
am 09.03.2008 02:38:55 von jonllmsed
------=_Part_1027_7387976.1205026735104
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Sorry. I can't really help you with server and PHP installation and
configuration issues.
I use XAMPP w/ a separate installation of MySQL.
http://www.apachefriends.org/en/xampp.html
But, find the following in your php.ini:
extension_dir=...
extension=php_mysql.dll
You may already have an "ext/" folder, just not where you were thinking it'd
be.
And, the extension may be commented out (semicolon at the beginning of the
line).
Theoretically, you should've recieved an "undefined function" error if it
was commented.
If the folder that extension_dir points to is empty or undefined, then I'd
say go download the Windows ZIP and rebuild the folder.
As for the script, do you have an example output?
If you're up for it, I wrote test script that outputs a few more details.
header('Content-type: text/plain');
$hostname = 'localhost';
$mysql_login = 'admin';
$mysql_password = 'admin';
$dbname = 'sampleapp';
echo "PHP: " . phpversion() . "\n\n";
echo "Connecting to (MySQL) $hostname (user: $mysql_login)\n";
$link = @mysql_connect($hostname, $mysql_login, $mysql_password);
echo "--------------------------------\n";
echo "Status: " . serialize($link) . " ($link)\n";
echo "Error : '" . mysql_error() . "' (" . mysql_errno() . ")\n";
echo "\n";
echo "Server: " . @mysql_get_server_info() . "\n";
echo "Host : " . @mysql_get_host_info() . "\n";
echo "\n";
echo "Select database `$dbname`\n";
$dbselect = @mysql_select_db($dbname);
echo "--------------------------------\n";
echo "Status: " . serialize($dbselect) . " ($dbselect)\n";
echo "Error : '" . mysql_error() . "' (" . mysql_errno() . ")\n";
echo "\n";
echo "Closing connection\n";
$dbclose = @mysql_close($link);
echo "--------------------------------\n";
echo "Status: " . serialize($dbclose) . " ($dbclose)\n";
echo "Error : '" . mysql_error() . "' (" . mysql_errno() . ")\n";
?>
The output should be something like this:
PHP: 5.2.5
Connecting to (MySQL) localhost (user: admin)
--------------------------------
Status: i:0; (Resource id #2)
Error : '' (0)
Server: 5.0.45-community-nt
Host : localhost via TCP/IP
Select database `sampleapp`
--------------------------------
Status: b:1; (1)
Error : '' (0)
Closing connection
--------------------------------
Status: b:1; (1)
Error : '' ()
- Jon L.
On Sat, Mar 8, 2008 at 5:53 PM, Manysh 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?
> ----
>
> /*--------- 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. 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 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
> > >
> > >
> >
> >
>
------=_Part_1027_7387976.1205026735104--
Re: mysql_connect() Help
am 09.03.2008 04:16:47 von Manysh
Matt - you're right! I did the manual install and its "partially"
working now. I say partially because it works fine when I run it from
the command window however when I run it from the web browser I get a
blank page. I restarted Apache but that didn't help. The script is
pasted below. Am I missing from the Apache side now? I have configured
http.conf too... is there anything else I need to take care of?
Thanks
----
/*--------- DATABASE CONNECTION INFO---------*/
$hostname="localhost";
$mysql_login="testuser";
$mysql_password="testuser";
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 7:22 PM, Matt Anderton wrote:
> 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 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?
> > ----
> >
> > /*--------- 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. 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 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
> >
> >
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_connect() Help
am 09.03.2008 04:57:33 von Matt Anderton
------=_Part_5410_15462738.1205035053595
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
httpd.conf should have something like this:
PHPIniDir "C:/Program Files/PHP/"
LoadModule php5_module "C:/Program Files/PHP/php5apache2.dll"
AddType application/x-httpd-php .php
.... but all that should have been taken care of by the PHP installer.
-- matt
On Sat, Mar 8, 2008 at 9:16 PM, Manysh wrote:
> Matt - you're right! I did the manual install and its "partially"
> working now. I say partially because it works fine when I run it from
> the command window however when I run it from the web browser I get a
> blank page. I restarted Apache but that didn't help. The script is
> pasted below. Am I missing from the Apache side now? I have configured
> http.conf too... is there anything else I need to take care of?
> Thanks
> ----
>
> /*--------- DATABASE CONNECTION INFO---------*/
> $hostname="localhost";
> $mysql_login="testuser";
> $mysql_password="testuser";
>
> 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 7:22 PM, Matt Anderton
> wrote:
> > 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 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?
> > > ----
> > >
> > > /*--------- 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. 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 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
> > >
> > >
> >
> >
>
------=_Part_5410_15462738.1205035053595--
Re: mysql_connect() Help
am 09.03.2008 05:21:12 von Manysh
Awesome... that worked! The PHPIniDir was pointing to my earlier
installation. Thanks Matt and Jon! Your help is much appreciated.
Jon, thanks for sending the script.
Manysh
On Sat, Mar 8, 2008 at 9:57 PM, Matt Anderton wrote:
> httpd.conf should have something like this:
>
> PHPIniDir "C:/Program Files/PHP/"
> LoadModule php5_module "C:/Program Files/PHP/php5apache2.dll"
> AddType application/x-httpd-php .php
>
> ... but all that should have been taken care of by the PHP installer.
>
> -- matt
>
>
>
> On Sat, Mar 8, 2008 at 9:16 PM, Manysh wrote:
>
> > Matt - you're right! I did the manual install and its "partially"
> > working now. I say partially because it works fine when I run it from
> > the command window however when I run it from the web browser I get a
> > blank page. I restarted Apache but that didn't help. The script is
> > pasted below. Am I missing from the Apache side now? I have configured
> > http.conf too... is there anything else I need to take care of?
> > Thanks
> >
> > ----
> >
> > /*--------- DATABASE CONNECTION INFO---------*/
> > $hostname="localhost";
> > $mysql_login="testuser";
> > $mysql_password="testuser";
> >
> >
> > 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 7:22 PM, Matt Anderton wrote:
> > > 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 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?
> > > > ----
> > > >
> > > > /*--------- 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. 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 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
> > > >
> > > >
> > >
> > >
> >
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php