Author Topic: Unable to connect to mysql database  (Read 3699 times)

Gametaku

  • .
  • Founders
  • Posts: 168
  • Karma: +13/-4
  • .
Unable to connect to mysql database
« on: September 08, 2006, 09:39:31 PM »
I've deciced that I want to mess around with php and mysql some more so I went and installed Apache 2.2.3 PHP 4.4.4   and mySql 5.0.24.  Everything seems to be set up ok, however I keep getting this message:

Quote
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in E:\web\exer.php on line 2
Client does not support authentication protocol requested by server; consider upgrading MySQL client

I'm using the following php
Code: (php) [Select]
<?php
mysql_connect
("localhost""taku""ethic") or die(mysql_error());
echo 
"Connected to MySQL<br />";
?>

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.

Gametaku

  • .
  • Founders
  • Posts: 168
  • Karma: +13/-4
  • .
Re: Unable to connect to mysql database
« Reply #2 on: September 09, 2006, 03:43:07 PM »
http://dev.mysql.com/doc/refman/5.0/en/old-client.html

Yea I ened up updating the php version I was using, but now I can't figure out why this dosn't work, I have a data base named exercise, with a table named exer.  The exer table contains three colums:
 id that is auto incremented,
name - a varchar
type - tinyint with a default value of 0;

Code: (php) [Select]
<?php
if ($submit) {
  
// process form
  
$db mysql_connect("localhost""taku""ethic");
  
mysql_select_db(exercise);
  
$sql "INSERT INTO exer SET name=$first";
  
$result mysql_query($sql);
  echo 
"Thank you! Information entered.\n";
} else{
  
// display form
  
?>

  <form method="post" action="<?php echo $PHP_SELF?>">
  Name :<input type="Text" name="first"><br>
  <input type="Submit" name="submit" value="Enter information">
  </form>
  <?php
// end if
?>

[/cdoe]

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Unable to connect to mysql database
« Reply #3 on: September 09, 2006, 05:40:16 PM »
Where is $first being defined?

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Unable to connect to mysql database
« Reply #4 on: September 09, 2006, 09:41:25 PM »
should "exercise" maybe have quotes around it?

mysql_select_db(exercise)

also, if you're using INSERT you need to change your query

INSERT INTO exer (name) VALUES ('$first')

they way you did it is if you are updating an existing record
ie:
UPDTATE exer SET name=$first WHERE primaryKey = 'somevalue'
« Last Edit: September 10, 2006, 10:55:42 PM by micah »
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Gametaku

  • .
  • Founders
  • Posts: 168
  • Karma: +13/-4
  • .
Re: Unable to connect to mysql database
« Reply #5 on: September 10, 2006, 02:56:50 PM »
I tried changing the line
$sql = "INSERT INTO exer SET name=$first"; as you suggest micah but the only resault I recived from that was that when I would click summit the page would become blank, refreshing it keep it the same but clicking back or entering the address again would bring back the form.   

Anyways this is the sample code I was working from if that helps,  it was not tested since I didn't feel like setting up a database to use with it.
Code: (php) [Select]
<html>
<body>
<?php
if ($submit) {
  
// process form
  
$db mysql_connect("localhost""root");
  
mysql_select_db("mydb",$db);
  
$sql "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')";
  
$result mysql_query($sql);
  echo 
"Thank you! Information entered.\n";
}
 else{
  
// display form
  
?>

  <form method="post" action="<?php echo $PHP_SELF?>">
  First name:<input type="Text" name="first"><br>
  Last name:<input type="Text" name="last"><br>
  Address:<input type="Text" name="address"><br>
  Position:<input type="Text" name="position"><br>
  <input type="Submit" name="submit" value="Enter information">
  </form>
  <?php
// end if
?>

</body>
</html>

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: Unable to connect to mysql database
« Reply #6 on: September 12, 2006, 01:50:40 AM »
that code will not work without register_globals turned 'On'.  In recent PHP versions this is turned off by default for security reasons in your php.ini file.  You can turn it on, which is not a good idea, or you have to pull your variables values out of the request yourself.

$first = $_REQUEST['first'] or $first = $_POST['first']

I find a better source for example code...