Re: MySQL problem

From: Date: Mon, 31 Dec 2001 02:55:40 +0000
Subject: Re: MySQL problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-79092@lists.php.net to get a copy of this message
Thanks so much guys, It was my user permissions all along. Funnily enough the book gives you guidelines on how to set them up, and sets up a fair few... but for some reason they selected the wrong user to use. Thanks very much for your help David and Brian- much appreciated. Yours, GF ----- Original Message ----- From: David Jackson To: goodfella_gf@hotmail.com Cc: david.j.jackson@pickledbeans.com ; php-general@lists.php.net Sent: Monday, December 31, 2001 2:41 AM Subject: Re: [PHP] MySQL problem I almost forgot add a or mysql_error() for each line like this: <?php // database connect script $dbhostname = "localhost"; $dbuser = "db_user_name"; $dbpasswd = "db_password"; $dbname= "db_name"; $link = mysql_connect("$dbhostname", "$dbuser", "$dbpasswd") echo mysql_error(); mysql_select_db("$dbname") echo mysql_error(); ?> This will return "human readable error messges" Can you onto mysql database from command. mysql -u root -p mysql or mysql -u root mysql # A root password isn't usally get during install. if so: >select user,host,password from user; then: select user,host,db from db; My quesss you don't have any permission for the databases or to connect to local host. If this is correct do: GRANT ALL on db_name.* TO you@local host idendified by 'your_password'; > Hiya, > > Thanks for the quick reply. I used the PHP manual example and it > connects to the database successfully but cannot select the database. > > I'm not sure why this is? I've looked hard at it and I cannot see where > I have gone wrong. > > Thanks. > > GF. > ----- Original Message ----- > From: David Jackson > To: goodfella_gf@hotmail.com > Cc: php-general@lists.php.net > Sent: Monday, December 31, 2001 1:48 AM > Subject: Re: [PHP] MySQL problem > > > Here's the example from the PHP manual: > The tutorial here are very helpfull: > http://www.melonfire.com/community/columns/trog/ > > -- David > > <?php > // Connecting, selecting database > $link = mysql_connect("mysql_host", "mysql_login", > "mysql_password") > or die("Could not connect"); > print "Connected successfully"; > mysql_select_db("my_database") > or die("Could not select database"); > > // Performing SQL query > $query = "SELECT * FROM my_table"; > $result = mysql_query($query) > or die("Query failed"); > > // Printing results in HTML > print "<table>\n"; > while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { > print "\t<tr>\n"; > foreach ($line as $col_value) { > print "\t\t<td>$col_value</td>\n"; > } > print "\t</tr>\n"; > } > print "</table>\n"; > > // Closing connection > mysql_close($link); > ?> > > > > > > Hello, > > > > I am extremely new to MySQL and have never managed to get working > > smoothly with PHP before. I am trying really hard to understand how > > to work it, and am almost there. > > > > I have a problem which I do not know how to resolve and was > > wondering if anybody could help me. I have no idea what is wrong > > with the code and why I am getting the error message; > > > > Warning: Supplied argument is not a valid MySQL result resource in > > C:\apache\htdocs\sams\chapter10\results.php on line 47 > > > > I am currently using a book to aid me with MySQL, and this is an > > example from the book. It does not seem to work and I have no idea > > what I may have done wrong to obtain this warning. > > > > I have changed my login and password to question marks. > > > > <? > > > > if (!$searchtype || !$searchterm) > > > > { > > echo "You have not entered search details. Please go back and > > try > > again."; > > > > exit; > > > > } > > > > > > $searchtype = addslashes($searchtype); > > > > $searchterm = addslashes($searchterm); > > > > @ $db = mysql_pconnect("mesh", "bookorama", > > "bookorama123"); > > > > if (!$db) > > > > { > > echo "Error: Could not connect to database. Please try again > > later."; > > > > exit; > > > > } > > > > mysql_select_db("booktest"); > > > > $query = "select * from booktest where ".$searchtype." like > > '%".$searchterm."%'"; > > > > $result = mysql_query($query); > > > > $num_results = mysql_num_rows($result); > > > > echo "<p>Number of books found: ".$num_results."</p>"; > > > > for ($i=0; $i <$num_results; $i++) > > > > { > > > > $row = mysql_fetch_array($result); > > > > echo "<p><strong>".($i+1).". Title: "; > > > > echo stripslashes($row["title"]); > > > > echo "</strong><br>Author: "; > > > > echo stripslashes($row["author"]); > > > > echo "<br>ISBN: "; > > > > echo stripslashes($row["isbn"]); > > > > echo "<br>Price: "; > > > > echo stripslashes($row["price"]); > > > > echo "</p>"; > > > > } > > > > ?> > > > > The problem seems to be around the lines of code; > > > > $result = mysql_query($query); > > > > $num_results = mysql_num_rows($result); > > > > Any assistance is appreciated. > > > > Yours, > > > > GF. > > > > _________________________________________________________________ > > Chat with friends online, try MSN Messenger: > > http://messenger.msn.com > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net To > > contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > -- -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#79092) next »