Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001122

Re: [PHP] MySQL problem From: GoodFella (goodfella_gf <email protected>)
Date: 12/30/01

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 <email protected>
  Cc: david.j.jackson <email protected> ; php-general <email protected>
  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 <email protected> 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 <email protected>
> Cc: php-general <email protected>
> 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 <email protected>
> > For additional commands, e-mail: php-general-help <email protected> To
> > contact the list administrators, e-mail:
> > php-list-admin <email protected>
>
>
> --

  --

  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: php-general-unsubscribe <email protected>
  For additional commands, e-mail: php-general-help <email protected>
  To contact the list administrators, e-mail: php-list-admin <email protected>