Jump to content

Please help a newbie


Weiss

Recommended Posts

I am lost! please help:

Hello all, i'm new to this, i would appriciate someone helping me access my sql with php on localhost. ive installed MAMP, i have created databases in my sql. now im trying to reach it thru the php code:

<?php
//Step1
 $db = mysqli_connect('localhost','root','1234','learnning_over_here')
 or die('Error connecting to MySQL server.');
?>

<html>
 <head>
 </head>
 <body>
 <h1>PHP connect to MySQL</h1>
 
<?php
//Step2
$query = "SELECT * FROM table_name";
mysqli_query($db, $query) or die('Error querying database.');
?>

</body>
</html>

i have no idea why but it just woldnt connect. ive been trying all day but.. not working. what am i doing wrong?

Link to comment
Share on other sites

Place the following code before you make your call to the mysqli_connect( ) function and see if it does not give you a better clue:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Roddy

Link to comment
Share on other sites

First- thank you very much for the help!. this is the code now:

<?php
//Step1
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

 $db = mysqli_connect('localhost','root','arr4shed','aliens_abduction', 3306)
 or die('Error connecting to MySQL server.');
?>

<html>
 <head>
 </head>
 <body>
 <h1>PHP connect to MySQL</h1>
 
<?php
//Step2
$query = "SELECT * FROM table_name";
mysqli_query($db, $query) or die('Error querying database.');
?>

</body>
</html>

 

this is the result in the browser:

PHP connect to MySQL

Error querying database.

 

any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...