Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a folder inside the wamp server setup end as "android_connect" and have uploaded my php files there. you can see the file path if you want in the errors below.. the files are :

db_config.php
PHP
<?php
define('DB_USER',"root");
define('DB_PASSWORD',"vikrant");
define('DB_DATABASE',"sys");
define('DB_SERVER',"Local instance wampmysqld64");
?>;



db_connect.php
PHP
<?php
class DB_CONNECT{
	function _construct(){
		$this->connect();
	}
	function _destruct(){
		$this->close();
	}
	function connect(){
		require_once_DIR_.'/dbconfig.php';
		$con=mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
		$db=mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
		return $con;
	}
	function close(){
		mysql_close();
	}
}
?>;




get_all_products.php
PHP
<?php
$response=array();
require_once_DIR_.'/db_connect.php';
$db=new DB_CONNECT();
$result=mysql_querry("SELECT * FROM users") or die(mysql_error());
if(mysql_num_rows($result)>0){
	$response["products"]=array();
	while($row=mysql_fetch_array($result)){
		$product=array();
		$product["pid"]=$row["pid"];
		$product["name"]=$row["name"];
		$product["price"]=$row["price"];
		$product["description"]=$row["description"];
		$product["created_at"]=$row["created_at"];
		$product["updated_at"]=$row["updated_at"];
		array_push($response["products"],$product);
	}
	$response["success"]=1;
	echo json_encode($response);
}else{
	$response["success"]=0;
	$response["message"]="No Product Found.";
	echo json_encode($response);
}
?>;


which is giving errors:
Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\android_connect\get_all_products.php on line 5

Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\wamp64\www\android_connect\get_all_products.php on line 5

Warning: mysql_query(): A link to the server could not be established in C:\wamp64\www\android_connect\get_all_products.php on line 5






These are some of many files i have tried uploading. Please help and thank you in advance.

What I have tried:

Tried rewritng the code and reuploading it..
Posted
Updated 1-Jan-17 19:18pm
v3

1 solution

Quote:
Notice: Use of undefined constant require_once_DIR_ - assumed 'require_once_DIR_' in C:\wamp64\www\android_connect\get_all_products.php on line 3
Fatal error: Class 'DB_CONNECT' not found in C:\wamp64\www\android_connect\get_all_products.php on line 4

Instead of
require_once_DIR_
it should be :
require_once __DIR__
PHP: Magic constants - Manual[^]
Instead of
respose = array();
I think it should be
$response = array();

As I mentioned before, double underline!
Instead of
function _construct()
it should be
function __construct()

Instead of
function _destruct()
it should be
function __destruct()

Quote:
Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\wamp64\www\android_connect\get_all_products.php on line 5
Are you sure you have set a password for the root account?
Quote:
Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
means mysql_query will not be supported in future php versions, in fact it has been removed from php 7. If you are still using php 5, it should work. PHP: Choosing an API - Manual[^]
 
Share this answer
 
v5
Comments
Member 12901284 2-Jan-17 1:19am    
Please Look at my question after I improved it.. Your solution worked thank you.
Peter Leow 2-Jan-17 1:32am    
What happens to the previous question?
Member 12901284 2-Jan-17 3:04am    
I tried the solution and it worked but had some other errors which I improved the question.
Peter Leow 2-Jan-17 3:09am    
You have to be patient, do one thing at a time. You are putting all mistakes together, some mistakes inevitably cause another one. They are all entangled now and you cannot really differentiate the causes from the effects. I suggest to start from scratch, do a small piece, verify that it works, then move on to another. Good luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900