Posted by: tonyteaching | January 24, 2009

to Configure PHP working with MySQL

0. Modify ‘php.ini’

    ;extension=php_mysql.dll

    To enable the MySQL extension, delete the semi-colon (;) at the beginning of that line.

    Also, ensure that the files php_mysql.dll and libmysql.dll (copy this file from main directory “\php\” to “php\ext”) in directory can be reached by php by modifying and uncommenting the line:

extension_dir = "C:\php\ext\"

  1. Next we must add the PHP directory to the Windows PATH. To do this, click: Start > My Computer > Properties > Advanced > Environment Variables. Under the second list (System Variables), there will be a variable called “Path”. Select it and click “Edit”. Add “;C:\php” to the very end of the string and click “OK”.
  2. Restart your computer for the changes to take effect.
  3. Create a new file in your “htdocs” directory called “mysql_test.php”.
  4. Copy the following code into “mysql_test.php” and click save. (Make sure to replace the MYSQL_PASS constant with the MySQL Password you specified during the MySQL installation).
    <?php# Define MySQL Settings

    define(“MYSQL_HOST”, “localhost”);

    define(“MYSQL_USER”, “root”);

    define(“MYSQL_PASS”, “therootpassword”);

    define(“MYSQL_DB”, “smsegov”);

    $conn = mysql_connect(“”.MYSQL_HOST.””, “”.MYSQL_USER.””, “”.MYSQL_PASS.””) or die(mysql_error());

    mysql_select_db(“”.MYSQL_DB.””,$conn) or die(mysql_error());

    $sql = “SELECT * FROM smsegov”;

    $res = mysql_query($sql);

    while ($field = mysql_fetch_array($res))

    {

    $id = $field[‘id’];

    $sex = $field[‘sex’];

    echo ‘ID: ‘ . $field[‘id’] . ‘<br />’;

    echo ‘Sex: ‘ . $field[‘sex’] . ‘<br /><br />’;

    }

    ?>

  5. Open up Internet Explorer and type in “http://localhost/mysql_test.php&#8221;. check it out!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: