syngod Posted August 21, 2007 Share Posted August 21, 2007 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 More sharing options...
trq Posted August 21, 2007 Share Posted August 21, 2007 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 More sharing options...
syngod Posted August 21, 2007 Author Share Posted August 21, 2007 ok that is a little better i got table test does not exist so i may be able to work with that thanks peep Link to comment https://forums.phpfreaks.com/topic/65893-solved-php5-mysql5/#findComment-329404 Share on other sites More sharing options...
syngod Posted August 21, 2007 Author Share Posted August 21, 2007 you guys rule thanks Link to comment https://forums.phpfreaks.com/topic/65893-solved-php5-mysql5/#findComment-329411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.