Jump to content

[SOLVED] php5 mysql5


syngod

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.