Re: Select DataBase Mysql Problem
| From: | Tom Rogers | Date: | Sun, 23 Mar 2003 12:03:09 +0000 |
| Subject: | Re: Select DataBase Mysql Problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140752@lists.php.net to get a copy of this message | ||
Hi,
Sunday, March 23, 2003, 1:26:04 PM, you wrote:
MA> Hi everyone,
MA> FIRST THANKX FOR ANY HELP !!
MA> and THANKX FOR READING :)
MA> I'm a reall newbie on PHP and i'm build a php app to connect into a mysql
MA> database.. but i cannot select the database
MA> i have build the database, and created a user
MA> with :
MA> create database mydatabase;
MA> use mydatabase;
MA> create tb_users ( userid varchar(20), userpassword varchar(20 );
MA> grant select, update, insert, delete on mydatabase.* to myuser@localhost
MA> IDENTIFIED BY "mypassword";
MA> then flush priveliges...
MA> I tested the user on mysql and it work correcly for my the pretended database
MA> NOTES:
MA> O.S. Linux
MA> Mysql : compiled the most recent stable 4.0.12
MA> Php was compiled by SuSe on SuSe 8.0
MA> Php is connected into mysql via socks (configured on /etc/php.ini)
MA> to test the set up i have used the php.net manual example to connect into the
MA> mysql database i manage to connect into mysql but i cannot select the database
MA> can this be my mistake or can it be a software problem ?
MA> here is the php programa
MA> <?php
MA> $DB_HOST = "localhost";
MA> $DB_USER = "myuser";
MA> $DB_PASSWORD = "mypassword";
MA> $DB_NAME = "mydatabase";
MA> /* Connecting, selecting database */
MA> $link = mysql_connect("$DB_HOST", "$DB_USER",
MA> "$DB_PASSWORD") or
MA> die("Could not connect<br>");
MA> print "Connected successfully<br>";
MA> mysql_select_db("$DB_NAME", $link) or die("Could not select
MA> database<br>");
MA> /* Performing SQL query */
MA> $query = "SELECT * FROM tb_users";
MA> $result = mysql_query($query) or die("Query failed<br>");
MA> /* Printing results in HTML */
MA> print "<table>\n";
MA> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
MA> print "\t<tr>\n";
MA> foreach ($line as $col_value) {
MA> print "\t\t<td>$col_value</td>\n";
MA> }
MA> print "\t</tr>\n";
MA> }
MA> print "</table>\n";
MA> /* Free resultset */
MA> mysql_free_result($result);
MA> /* Closing connection */
MA> mysql_close($link);
?>>
MA> Stay Happy
MA> Miguel Angelo
MA> ------- End of Forwarded Message -------
Add a call to mysql_error() to find out what mysql does not like.
mysql_select_db("$DB_NAME", $link) or die("Could not select database:
".mysql_error()."<br>");
--
regards,
Tom