-
connect my sql with php
Hi all,
I need to learn Mysql, in dos
C:\Program Files\MySQL\MySQL Server 4.1\bin>mysql -uroot -p mysql
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.14-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE first_test;
Query OK, 1 row affected (0.00 sec)
mysql> use first_test
Database changed
mysql> CREATE TABLE people (
-> id int UNIQUE NOT NULL,
-> first_name varchar(40),
-> surname varchar(50),
-> PRIMARY KEY(id)
-> );
Query OK, 0 rows affected (0.06 sec),
but when I try the following code
<?php
$username = "uroot";
$password = "123456";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to mysql");
print "connected to mysql<br>";
$selected = mysql_select_db("first_test",$dbh)
or die("Could not select first_test");
if (mysql_query("insert into people values('5','Hazel','Burger')")) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>
I always got error at unable to connect mysql.
in MS sql is easy to find is password, where to find the password or set new password in My sql? please help!
thank you
________
No2 vaporizer
Last edited by sql; 03-06-2011 at 01:52 AM.
-
hi,
please check variable $username in PHP
please reply $username="uroot" with $username="root"
thnk's
-
Hi,
Thank you for the reply, but
what ever I use root or uroot I got
Can't connect to MySQL server on 'localhost' (10061)
if I try
Code:
<?
$user="uroot";
$password="Hi";
$database="test";
mysql_connect('localhost:3306',$user,$password)or die(mysql_error());
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();
?>
I got Access denied for user 'uroot'@'localhost' (using password: YES)
what is wrong??
Thank you
________
Buy Hot Box
Last edited by sql; 03-06-2011 at 01:53 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|