WAMP server problem to connect php script
Posted by: ballu (---.pol.net.in)
Date: July 01, 2016 09:23AM

Problem with WAMP Server, In my Local system i success fully install the WAMP Server 3.0.4.
Then my problem was to connect the PHP script to WAMP Server database, I am trying connect the data base gives an error.


>i create a folder under "www" my folder name was "webapps"
>then under this "webapps" folder i had create a text file with name init.php,in this i had write code to connect data base and to display a message like... Data base connection success....
>then i connect the data base it not display messages, just it simply display my code as it is.
>my php code was

><?php
$db_name="webappdb";
$sql_name="root";
$sql_pass="root";
$server_name="localhost";
$con=mysqli_connect($server_name,$sql_name,$sql_pass,$db_name);
if(!$con){
echo"Database Connection Error...".mysqli_connect_error();
}
else{
echo"<h3>Database Connection Success....</h3>"
}
?>

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: Otomatic (Moderator)
Date: July 01, 2016 10:04AM

Hi,

> just it simply display my code as it is.

In the adress bar type : 'http://localhost/webapps/init.php'

Note: at the beginning of the file you wrote '><?php' I think it is a typo, you need only '<?php'

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: RiggsFolly (Moderator)
Date: July 01, 2016 10:26AM

Hi again,

Unless you added a password to the `root` userid then by default there is not password on `root`.

So try this

<?php
$db_name="webappdb";
$sql_name="root";
$sql_pass="";
$server_name="localhost";
$con=mysqli_connect($server_name,$sql_name,$sql_pass,$db_name);

if(!$con){
    echo"Database Connection Error...".mysqli_connect_error();
} else{
    echo"<h3>Database Connection Success....</h3>"
}
?>


If this fails please paste the EXACT error message into your next post

Also REMEMBER you must run this now through your browser using `localhost/webapps/init.php`

You cannot run PHP code by doubleclicking on the `init.php` file name in windows explorer.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 1 time(s). Last edit at 07/01/2016 10:29AM by RiggsFolly.

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: ballu (---.pol.net.in)
Date: July 01, 2016 06:15PM

am also trying with out passing the
$sql_pass=" ";
then again it gives same error.
what i write the code in init.pht that code as it is display in the browser
am type like that only like ... localhost/webapps/init.php

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: ballu (---.pol.net.in)
Date: July 01, 2016 06:19PM

if am trying like what your saying then again it displays my code as the result
am trying this and

<?php
$db_name="webappdb";
$sql_name="root";
$sql_pass="root";
$server_name="localhost";

$con=mysqli_connect($server_name,$sql_name,$sql_pass,$db_name);

if(!$con){
    echo"Database Connection Error...".mysqli_connect_error();
} else {
    echo"<h3>Database Connection Success....</h3>"
}
?>
this also with out sql_pass=" ";
<?php
$db_name="webappdb";
$sql_name="root";
$sql_pass=" ";
$server_name="localhost";

$con=mysqli_connect($server_name,$sql_name,$sql_pass,$db_name);

if(!$con){
    echo"Database Connection Error...".mysqli_connect_error();
} else {
    echo"<h3>Database Connection Success....</h3>"
}
?>



Edited 1 time(s). Last edit at 07/02/2016 01:50PM by RiggsFolly.

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: Otomatic (Moderator)
Date: July 01, 2016 06:47PM

Hi,

Can you answer all the questions: READ BEFORE YOU ASK A QUESTION

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: WAMP server problem to connect php script
Posted by: RiggsFolly (Moderator)
Date: July 02, 2016 01:51PM

Try with

$sql_pass="";  // note no space in string

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.