Jump to content
alinash33

I don't have success connecting to database wampserver

Recommended Posts

Ok so I have installed Wamp server on windows 10.Details:Apache 2.4.23 - PHP 5.6.25 - MySQL 5.7.14

PHP 5.6.25 for CLI (Command-Line Interface).

I made a simple database in phpmyadmin to check connectivity to the database.

database name="news"

with one table

table="info_news"

I have the index.php in the www folder of wamp

The wamp Icon is green running on port 80

I tried 3 different codes to connect to database: old mysql connection,mysqli coonection,PDo connection

I didn't succeed to connect with either of them.

I stop trying with old mysql and pdo and I'm focused now on mysqli.

This is the code on my index.php:

<?php>
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "news";

$conn = new mysqli('localhost', 'root', ' ', 'news');

// Check connection
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
echo 'Connection OK';
$mysqli->close();

$myquery = "select * from info_news";
if (mysqli_query($conn, $myquery)) {
echo "Records retrieved.";
} else {
echo "Error : " . mysqli_error($conn);
}

?>
When I check this on the browser this is what I get:

Navigation to the webpage was canceled 

What you can try: 

Retype the address. 

 

I tried to change the localhost to '127.0.0.1' but the result is the same.

What did I miss?

What is my mistake?

I really want just this simple success of connection.

Edited by gizmola
making my eyes bleed less

Share this post


Link to post
Share on other sites

Could it be something to do with the syntax error?

  • Like 2

Share this post


Link to post
Share on other sites

Navigation to the webpage was canceled

What you can try:

Retype the address.

You might also try using a browser that doesn't re-interpret system error messages quite so blatantly.

Share this post


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