RE: [PHP] Re: Connecting to a DB using PHP and mysql...
| From: | Rick Emery | Date: | Tue, 02 Apr 2002 19:12:05 +0000 |
| Subject: | RE: [PHP] Re: Connecting to a DB using PHP and mysql... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-91198@lists.php.net to get a copy of this message | ||
I assume that instead of johndoe, you used the real user name that you have
in your script
-----Original Message-----
From: Anthony Ritter [mailto:tony@gonefishingguideservice.com]
Sent: Tuesday, April 02, 2002 2:06 PM
To: Rick Emery
Subject: Rick...
Rick,
After typing in:
mysql> SHOW GRANTS FOR johndoe@localhost;
I get an ERROR 1064
Regards,
TR
..........................................
----- Original Message -----
From: Rick Emery <remery@excel.com>
To: 'Anthony Ritter' <tony@gonefishingguideservice.com>;
<php-general@lists.php.net>
Sent: Tuesday, April 02, 2002 12:31 PM
Subject: RE: [PHP] Re: Connecting to a DB using PHP and mysql...
> at the mysql command line, type:
> mysql> show grants for johndoe@localhost;
>
> what does it show?
..................................
>
> -----Original Message-----
> From: Anthony Ritter [mailto:tony@gonefishingguideservice.com]
> Sent: Tuesday, April 02, 2002 1:08 PM
> To: php-general@lists.php.net
> Subject: [PHP] Re: Connecting to a DB using PHP and mysql...
>
>
> Craig,
> I tried the following.
>
> I was able to connect to mysql but not to the database "contacts".
>
> TR
> .......................................................
>
> <HTML>
> <BODY>
> <?
> define("DATABASE_HOST", "localhost");
> define("DATABASE_USER", "johndoe");
> define("DATABASE_PASSWORD", "abc");
> define("DATABASE_NAME", "contacts");
>
> $connection=mysql_connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD);
> if(!$connection)
> {
> echo "Couldn't connect.";
> exit;
> }
> $db=mysql_select_db(DATABASE_NAME,$connection);
> if(!$db)
> {
> echo "Couldn't connect to the database.";
> exit;
> }
> $sql="SELECT * FROM leads";
> $mysql_result=mysql_query($sql, $connection);
> $num_rows=mysql_num_rows($mysql_result);
>
> if($num_rows==0)
> {
> echo "There is no information";
> }
> else
> {
> echo"<TABLE ALIGN=\"Center\" BORDER=\"1\">";
> echo"<TR><TH><FONT FACE =\"Arial\" SIZE=\"2\">First
> Name</TH><TH><FONT
FACE
> =\"Arial\" SIZE=\"2\">Last Name</TH><TH><FONT FACE
> =\"Arial\"
> SIZE=\"2\">email</TH><TH><FONT FACE =\"Arial\"
> SIZE=\"2\">State</TH>";
>
> while($row=mysql_fetch_array($mysql_result))
> {
> $fname=$row["fname"];
> $lname=$row["lname"];
> $email=$row["email"];
> $state=$row["state"];
> $ID=$row["ID"];
> echo " <TR><TH><FONT FACE =\"Arial\"
> SIZE=\"2\">$fname</TH><TH><FONT FACE
> =\"Arial\" SIZE=\"2\">$lname</TH><TH><FONT FACE
> =\"Arial\"
> SIZE=\"2\">$email</TH><TH><FONT FACE =\"Arial\"
> SIZE=\"2\">$state</TH></TR>";
> }
> }
> mysql_close($connection);
> ?>
> </BODY>
> </HTML>
> ...........................................
>
> Craig Donnelly wrote in message:
> Try this for your connection:
> ............................................
> <?
> >
> > // Database constants
> > define("DATABASE_HOST", "localhost");
> > define("DATABASE_USER", "root");
> > define("DATABASE_PASSWORD", "*YOUR_PASS*");
> > define("DATABASE_NAME", "*YOUR_DB_NAME*");
> >
> > // Establish connection
> > $dbLink = mysql_connect(DATABASE_HOST, DATABASE_USER,
DATABASE_PASSWORD);
> > if(!$dbLink) {
> > print "Unable to connect to the database, please contact
Sysadmin
> > asap.";
> > } else {
> > $dbUse = mysql_select_db(DATABASE_NAME, $dbLink);
> > }
> >
> > ?>
> >
>
> --------------------------------------------------------------------------
> --
> > Hope it helps ya,
> >
> > Craig
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> ---
> [This E-mail scanned for viruses by IAS, an Archiventure Company]
>
>
---
[This E-mail scanned for viruses by IAS, an Archiventure Company]