Jump to content

Recommended Posts

hey guys i have a php mysql problem.  ok i have both installed and working separately but when i try to access mysql through php i get blank pages and i can't find where the problem is.  i have the mysql.dll files working in php.ini but when i write a script to test the connection i get nothing but white page.

 

just encase i don't know how to write php here is the code.

 

<?php

# Define MySQL Settings
define("MYSQL_HOST", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASS", "password");
define("MYSQL_DB", "test");

$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 test";
$res = mysql_query($sql);

while ($field = mysql_fetch_array($res))
{
$id = $field['id'];
$name = $field['name'];

echo 'ID: ' . $field['id'] . '<br />';
echo 'Name: ' . $field['name'] . '<br /><br />';
}

?>

and the password should be what i use to access mysql.  any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/65893-solved-php5-mysql5/
Share on other sites

Try...

 

<?php

  # Define MySQL Settings
  define("MYSQL_HOST", "localhost");
  define("MYSQL_USER", "root");
  define("MYSQL_PASS", "password");
  define("MYSQL_DB", "test");

  $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 test";
  if ($res = mysql_query($sql)) {
    if (mysql_num_rows($res)) {
      while ($field = mysql_fetch_array($res)) {
        echo 'ID: ' . $field['id'] . '<br />';
        echo 'Name: ' . $field['name'] . '<br /><br />';
      }
    } else {
      echo "No results found";
    }
  } else {
    echo mysql_error();
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/65893-solved-php5-mysql5/#findComment-329401
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.