Ok i have build an app that is Database oriented ( Mysql ), the thing is that it connect's to the Database from JSON php file and i want it to have multiple users with different UN and Pass.
I have non experience with Json files and i found some examples but can't combine them. Here are the codes:
<?php
$link = mysql_pconnect("host", "db_user", "db_password") or die("Could not connect");
mysql_select_db("db_name") or die("Could not select database");
$arr = array();
$rs = mysql_query("SELECT * FROM news");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo json_encode($arr);
?>
This is one way but it is not multi user.
<?php
header('Content-type: application/json');
if($_POST) {
if($_POST['username'] == '****' && $_POST['password'] == '*****') {
echo '{"success":1}';
} else {
echo '{"success":0,"error_message":"Username and/or password is invalid."}';
}
}else { echo '{"success":0,"error_message":"Username and/or password is invalid."}';}
?>
This is with multi user but not containing array.
<?php
$host = "************"; //Your database host server
$db = "****"; //Your database name
$user = "****"; //Your database user
$pass = "****"; //Your password
$connection = mysql_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}
else
{
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}
else
{
$query = "SELECT * FROM *****";
$resultset = mysql_query($query, $connection);
$records = array();
//Loop through all our records and add them to our array
while($r = mysql_fetch_assoc($resultset))
{
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
}
}
?>
and this is perfect but can't mix it with the second one.
Any idea how to do so?
mysql_*functions. I am not sure what you mean by "multi-user". DO you mean you want different mysql user/pw combos? If so, why?