Results 1 to 3 of 3

Thread: connect my sql with php

Threaded View

  1. #1
    Join Date
    Jul 2003
    Posts
    421

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •