Jump to content

Please help a newbie


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 post
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 post
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 post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...